我正在尝试修改当前代码以替换 MSWord 文档中的指定单词。整个想法是可行的,但仅适用于文档正文,而页眉和页脚中没有任何变化。您能告诉我我错在哪里吗?
先感谢您!
Sub FindAndReplace(ByVal FindWord, ByVal ReplaceWord)
WordApp.ActiveDocument.Range.Find.Execute FindText:=FindWord, Wrap:=1, ReplaceWith:=ReplaceWord, Replace:=2
End Sub
答案1
尝试:
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