I am trying to confirm if a document contains some text, the only problem is this text is in the Header. This is the code I am using which constantly returns false even though the text exists:
Set CurrentDoc = Documents.Open("a.doc")
With CurrentDoc.Sections(1).Headers(wdHeaderFooterFirstPage).Range.Find
.Text = "This is the text to find"
.Forward = True
.Execute
If (.Found = True) Then Debug.Print "Match"
End With
The following also doesn’t seem to work (I assume .Content doesn’t include header/footers):
With CurrentDoc.Content.Find
.Text = "This is the text to find"
.Forward = True
.Execute
If (.Found = True) Then Debug.Print "Match"
End With
Any help would be greatly appreciated.
I found the answer on this site and it’s a lot more complex than initially thought: http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm
The following code is from the site above, in addition to searching the entire document it includes text replace functionality: