Hi Experts,
I'm programming in VB6 / VBA and working with MS Word. My program has a paragraph range which I know has a field within it. However, I can't figure out where the field is in the range. Is it at the beginning? End? Somewhere in the middle? How many characters in? I know there is field (of one type or another) because I used the code below:
Dim fld as Word.Field
Dim rng as Word.Range
For Each fld In rng.Fields
If fld.Type = wdFieldPageRef Then
msgbox "FieldPageRef"
ElseIf fld.Type = wdFieldTOC Then
msgbox "Table of Contents"
elseif fld.type = wdFieldFootnoteRef
msgbox "Footnote"
ElseIf fld.Type = wdFieldTOA Or fld.Type = wdFieldIndex Then
msgbox "Other field"
End if
Next fld
That works fine... In some of the cases, eg Table of Contents, I know that the field is the whole paragraph (in which case there is no issue locating it). However, for others, like footnotes, I can't figure out where they are in the text. The only thing I can think of is to test one character at a time because once inside of a field, the above code doesn't find the field at all. However, that method would be very, very slow. Is there a better way?
Thanks in advance,
PatternNut
Start Free Trial