sheeeng
05-17-2005, 11:51 PM
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.......
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
I want the Name, Student 1, Gender, Height data only.....but i get below results........
Word Document Contents:
1.7
Please advise....
Thanks.
Leonard.:friends:
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.......
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
I want the Name, Student 1, Gender, Height data only.....but i get below results........
Word Document Contents:
1.7
Please advise....
Thanks.
Leonard.:friends: