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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB/VBA: Searching the Winword Footnotes collection 1

Status
Not open for further replies.

paoconnell

Programmer
Jun 11, 2002
41
US
Has someone out there figured out a good way to search for a keyword in the Footnotes() collection (if any) in a Word (2000 or newer) document? I already have code that searches for each occurrence that keyword in the ActiveDocument.Content range.

The footnotes in a document do not seem to be part of .Content, so occurrences of the keyword in each Footnote aren't found.

I can access the Footnotes this way:

FootnoteCount = WordObj.ActiveDocument.Footnotes.Count
If FootnoteCount > 0 Then
MsgBox "Footnotes found, count =" & CStr(FootnoteCount)

For i = 1 To FootnoteCount
'*** I suspect this is my problem here
Set DocRange = WordObj.ActiveDocument.Footnotes(i).Range

Set DocRangeFind = DocRange.Find

With DocRangeFind
.Forward = True
.MatchCase = True
.MatchWholeWord = True
.Wrap = 0

'find first occurrence of Tag, if any

.Execute FindText:=Tag, Replace:=0 'wdReplaceNone

'Only search further if the Tag is in there somewhere

Do While .Found
'app specific stuff removed


'Get next word that matches Tag, if any.

.Execute FindText:=Tag, Replace:=0 'wdReplaceNone
Loop
End With
Next i
End If

There seems to be no way to set the range to the entire footnote. I know that the string in Tag is in at least two footnotes in the sample document, but they're not found.

Furthermore, document Endnotes are in a similar collection, and they probably need to be searched as well.

Anyone found a solution?



Pat O'Connell
 
Hi Pat,

The Find Object belongs to the Selection Object. If you want to use it to search Footnotes, you must first Select the Footnotes Story ..

Code:
[blue]ActiveDocument.StoryRanges(wdFootnotesStory).Select
With Selection.Find
    :
    etc[/blue]

Alternatively, you can use the Find Object of a Range Object ..

Code:
[blue]Set FootNotes = ActiveDocument.StoryRanges(wdFootnotesStory)
With FootNotes.Find
    :
    etc[/blue]

There is, amongst others (about 13 in all, I think) a similar EndNotes Story.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Thanks for the pointer. Once I knew about StoryRanges, I found another article that details how to do searches in the other Stories. Incidentally, the article warns not to search the main Document as a Story, as that can be pretty slow.

Pat O'Connell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top