Results 1 to 7 of 7

Thread: Solved: Extract Selected Data from Word to Excel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Mentor sheeeng's Avatar
    Joined
    May 2005
    Location
    Kuala Lumpur
    Posts
    392
    Location

    Exclamation Solved: Extract Selected Data from Word to Excel

    Hi all,

    I face problem while I want to extract selected data out from Word to Excel.

    My word doc is below (contains a table)....

    -------------------------------------
    Student 1: Leonard Lee
    Name Leonard
    Gender Male
    Age 20
    Address Kuala Lumpur
    Email leonardleeshengsheng@yahoo.com
    Height 1.7
    Weight 65
    Comment Good Student
    Type Pessimistic
    -------------------------------------

    This is the macro i had created in excel.......
    [vba]Sub OpenAndReadWordDoc()
    ' assumes that the previous procedure has been executed
    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
    Dim tString As String, tRange As Word.Range
    Dim p As Long, r As Long
    Workbooks.Add ' create a new workbook
    With Range("A1")
    .Formula = "Word Document Contents:"
    .Font.Bold = True
    .Font.Size = 14
    .Offset(1, 0).Select
    End With
    r = 3 ' startrow for the copied text from the Word document
    Set wrdApp = CreateObject("Word.Application")
    'wrdApp.Visible = True
    Set wrdDoc = wrdApp.Documents.Open("D:\Profiles\stu678\Desktop\Data.doc")
    ' example word operations
    With wrdDoc
    For p = 1 To .Paragraphs.Count
    Set tRange = .Range(Start:=.Paragraphs(p).Range.Start, _
    End:=.Paragraphs(p).Range.End)
    tString = tRange.Text
    tString = Left(tString, Len(tString) - 1)
    ' exclude the paragraph-mark
    ' check if the text has the content you want
    If InStr(1, tString, "1") > 0 Then
    ' fill into active worksheet
    ActiveSheet.Range("A" & r).Formula = tString
    r = r + 1
    End If
    Next p
    .Close ' close the document
    End With
    wrdApp.Quit ' close the Word application
    Set wrdDoc = Nothing
    Set wrdApp = Nothing
    ActiveWorkbook.Saved = True
    End Sub[/vba]
    I want the Name, Student 1, Gender, Height data only.....but i get below results........

    Word Document Contents:
    1.7

    Please advise....

    Thanks.

    Leonard.
    Last edited by Killian; 05-18-2005 at 02:14 AM. Reason: Formatting & VBA tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •