在Word文档页脚中查找和替换

问题描述 投票:0回答:2

我在Excel中具有用于编辑和修改Word文件的VBA代码。

我现在正在尝试在Word文件的页脚中查找和替换文本。我无法弄清楚逐步浏览Word文件故事情节的命令。

我知道

参数不可选

突出显示查找。

Set wrdDoc = wrdApp.Documents.Open(ThisWorkbook.Path & "\Raw\Template\" &  strFile, ReadOnly:=True)
...
Dim myStoryRange As Range
For Each myStoryRange In wrdDoc.StoryRanges
    myStoryRange.Find.Execute FindText:=strField, ReplaceWith:=strValue, Replace:=wdReplaceAll, Wrap:=wdFindContinue
Next myStoryRange
excel vba word-vba
2个回答
0
投票

至少在我的文档中找到了解决方案。

wrdDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range.Find.Execute FindText:=strField, Format:=False, ReplaceWith:=strValue, Replace:=wdReplaceAll, Wrap:=wdFindContinue

我还不得不将行移动到代码的较早部分才能工作,因为某些原因,我要在页脚中替换的strField值从未“到达”代码中的该行。


0
投票

是的,所以在LOADS失败之后,其他人一直在尝试,这对我有用。我的目标是用超简单替换单词标题中的字符串:

WordDoc.Sections(1).Headers(1).Range.Find.Execute FindText:=TagName,
 Format:=False,
 ReplaceWith:=TagValue,
 Replace:=wdReplaceAll,
 Wrap:=wdFindContinue

为那些遇到类似需求的提要发布。

© www.soinside.com 2019 - 2024. All rights reserved.