PDA

View Full Version : Solved: Word to Excel



vzachin
12-21-2010, 07:52 PM
hi,

i know how to open a .txt file to extract data but i don't know how to read a .doc file to do the same.
basically, i need to extract 2 fields (a name and 4 numerics) in a .doc file and place it into the excel sheets column a & b. the data is in a table and and is always on the same row.

i can open each file but i don't know how to read the row for the data.

attached is the .doc file. the field i'm interested in is next to the field marked CONTACT:, and the last field in the same row.

thanks
zach

Bob Phillips
12-22-2010, 01:33 AM
Automating Word is simple enough



Dim wrdApp As Object
Dim wrdDoc As Object

Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("C:\test.doc")

'do something

wrdDoc.Close
Set wrdDoc = Nothing
wrdApp.Quit
Set wrdApp = Nothing


Are those fields bookmarks?

vzachin
12-22-2010, 04:52 AM
hi bob, the fields are not bookmarks...

zach

Tinbendr
12-22-2010, 03:13 PM
Sub ReadContact()
Dim wrdApp As Object
Dim wrdDoc As Object

Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("C:\test.doc")
With wrdDoc.Tables(1)
'Use Left() to strip off End-of-Cell marker
Range("B2").Value = Left(.Cell(2, 2).Range.Text, _
Len(.Cell(2, 2).Range.Text) - 2)
Range("C2").Value = Left(.Cell(2, 4).Range.Text, _
Len(.Cell(2, 4).Range.Text) - 2)
End With
wrdDoc.Close
Set wrdDoc = Nothing
wrdApp.Quit
Set wrdApp = Nothing
End Sub

vzachin
12-22-2010, 06:47 PM
hi Tinbendr,

works great!

thanks
zach