Real Software Forums
http://forums.realsoftware.com/

[Solved]Reading the contents of a textbox in a Word document
http://forums.realsoftware.com/viewtopic.php?f=6&t=46997
Page 1 of 1

Author:  Zudo [ Tue Feb 19, 2013 10:05 am ]
Post subject:  [Solved]Reading the contents of a textbox in a Word document

Hi,

Does anyone know how to loop through all of the textboxes in a word document and output the text they contain.
I have tried the following code but can not get it to work. I keep getting a TypeMismatchException error on the msgbox.

It doesn't help that the IDE does not show the TextFrame or the HasText after you have entered the period, followed by tab. Is this something missing in the IDE or am I doing something wrong?

Dim word as New WordApplication
Dim doc as WordDocument
Dim f As FolderItem

f = GetOpenFolderItem(FileTypes.ApplicationMsword)

If f Is Nil Then
Return
End If

if word is Nil then
MsgBox "Word failed to open"
return
end if

doc = word.Documents.Open(f.AbsolutePath)
word.Visible = True

word.Selection.Homekey(office.wdStory)

msgbox word.ActiveDocument.Shapes.Count

for i as integer = 1 to word.ActiveDocument.Shapes.Count
if word.ActiveDocument.Shapes(i).TextFrame.HasText then
msgbox word.ActiveDocument.Shapes(i).TextFrame.TextRange.Text
end if
next


EDIT:

In case anyone is interested. I needed to add the .Text to the end of the TextRange.
Can't seem to get to the msdn.microsoft.com website today so had to google loads to try and find the answer.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/