Reading Word TextBoxes and Transferring Contents to Excel

Y

yl358

So I have all these word documents with the same format. They have all
these textboxes that contain "name", "date", "state", "telephone #",
etc., respectively.

I'm trying to create a database using these .doc files. One way is to
manually open all the .doc files and manually type into Excel the name,
date, state, telephone, etc into each column. But this is tedious!

I'm sure there's a way for Excel to search all the textboxes from Word
and automatically transfer it all into one Excel database.

I found something on the web that converts Word Comments into Excel. I
think it would help in what I'm trying to do:

--------------------------------------------------------------
Public Sub PullWordNotes()

Dim WordApplication As Word.Application
Dim WordDocument As Word.Document
Dim DocumentPath As String
Dim TargetComment As Word.Comment
Dim DestSheet As Worksheet
Dim DestRow As Long

Set WordApplication = New Word.Application
DocumentPath = Application.GetOpenFilename(FileFilter:="Microsoft
Word Files (*.doc),*.doc", Title:="Select template narrative Word
document")
If DocumentPath = "False" Then
Exit Sub
End If

Set WordDocument = WordApplication.Documents.Open(DocumentPath,
ReadOnly:=True)

Set DestSheet = Sheets("Sheet1")
DestSheet.Cells.ClearContents
DestSheet.[A1] = "Comment"
DestSheet.[B1] = "Referenced Text"
DestRow = DestSheet.[A65536].End(xlUp).Row

For Each TargetComment In WordDocument.Comments
DestSheet.[A2:A65536].Cells(DestRow) = TargetComment.Range.Text
DestSheet.[B2:B65536].Cells(DestRow) = TargetComment.Scope.Text
Next TargetComment

WordDocument.Close False
WordApplication.Quit

End Sub

--------------------------------------------------------------

Now... that just transfers Comments from Word. I'm trying to transfer
Text Boxes from Word. I'm knowledgable in VBA, but I cannot frind the
TextBox counterpart to Comments. All I found was Controls,
ControlCollections, but I don't know how to make it work.

Anyone got any suggestions? Thanks
 
Y

yl358

Ok I solved the problem for those who want a solution:

Dim DestString As String
DestString = WordDocument.Shapes("Text Box
7").TextFrame.TextRange.Text

Now I have another problem, albeit minor one. The String always ends
with a square symbol. It looks like a small, blocky zero and always
appears at the end of every string that the .Text method returns.
What's up with this? I did the hard part already, so please help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top