怎样用VB代码实现查找替换word页眉里的文字
展开全部
参考这个代码替换页眉里的文字(注意这个代码只适用于奇偶页眉相同的情形):Sub ReplaceAllInHeader(strFind As String, strReplace As String) Dim oStoryRange As Range Set oStoryRange = ActiveDocument.StoryRanges(wdPrimaryHeaderStory) oStoryRange.Find.ClearFormatting oStoryRange.Find.Replacement.ClearFormatting With oStoryRange.Find .Text = strFind .Replacement.Text = strReplace .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With oStoryRange.Find.Execute Replace:=wdReplaceAllEnd Sub如果想针对全文进行替换(包括正文、普通页眉、奇偶页眉、普通页码、奇偶页码、脚注、尾注等等):Sub ReplaceAll(strFind As String, strReplace As String) Dim oStoryRange As Range For Each oStoryRange In ActiveDocument.StoryRanges oStoryRange.Find.ClearFormatting oStoryRange.Find.Replacement.ClearFormatting With oStoryRange.Find .Text = strFind .Replacement.Text = strReplace .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With oStoryRange.Find.Execute Replace:=wdReplaceAll Next End Sub
博思aippt
2024-07-20 广告
2024-07-20 广告
博思AIPPT是基于ai制作PPT的智能在线工具,它提供了4种AI制作PPT的方式,包括AI生成大纲、AI直接生成PPT、文本生成PPT、AI提炼word文档生成PPT,一站式集成多种AI生成PPT的方式,可满足办公用户的不同需求和使用场景...
点击进入详情页
本回答由博思aippt提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询