怎样用VB代码实现查找替换word页眉里的文字?
怎样用VB代码实现查找替换word页眉里的文字?比如页眉里面有“行程”的文字全部替换成“预定”,用vb代码如何实现?...
怎样用VB代码实现查找替换word页眉里的文字?
比如页眉里面有“行程”的文字全部替换成“预定”,用vb代码如何实现? 展开
比如页眉里面有“行程”的文字全部替换成“预定”,用vb代码如何实现? 展开
1个回答
展开全部
参考这个代码替换页眉里的文字(注意这个代码只适用于奇偶页眉相同的情形):
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:=wdReplaceAll
End 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
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:=wdReplaceAll
End 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 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT...
点击进入详情页
本回答由博思aippt提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |