paoconnell
Programmer
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
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