0

I'm trying to modify my current code to replace specified words in a MSWord document. The whole idea is working but only for the body of the document and nothing happening in the header or in the footer. Can you please advise me where am I wrong ?

Thank you in advance!

Sub FindAndReplace(ByVal FindWord, ByVal ReplaceWord)

WordApp.ActiveDocument.Range.Find.Execute FindText:=FindWord, Wrap:=1, ReplaceWith:=ReplaceWord, Replace:=2
End Sub
2

1 Answer 1

0

Try:

Sub FindAndReplace(ByVal FindWord, ByVal ReplaceWord)
Dim oStory as WordApp.Range
For Each oStory in WordApp.ActiveDocument.StoryRanges
    oStory.Find.Execute _
        FindText:=FindWord, ReplaceWith:=ReplaceWord, Wrap:=1, Replace:=2
Next oStory
Set oStory = Nothing
End Sub

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .