Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I obtain the Field.text from Word.Selection.Field?

Status
Not open for further replies.

capitano

Programmer
Jul 30, 2001
88
US
I'm trying to do the VB.NET --> Microsoft word automation thing. I have some hidden fields (index code fields) within the word document. I want to iterate through the fields and pull out the text for later processing:

Dim myfield as Word.Field
Dim myfieldstring As String
For Each myfield In .Selection.Fields
myfield.Select()
myfieldstring = myfield.Data.toString
MsgBox("This hidden field contains: " & myfieldstring)
Next

....
However, I get a run-time error on the line:
myfieldstring = myfield.Data.toString

Specific error: "The selection does not start in a field."

Does anybody know what I'm doing wrong? I can't figure it out. Thanks you,
Bryan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top