word如何批量替换字符
“张三”,“李四”,“王五”,“何六”四个名字位于文档不同地方并各自多次出现,怎样一次过把张三替换成李四,而李四替换成张三。同理,“王五”与“何六”互换。谢谢mkw007...
“张三”,“李四”,“王五”,“何六”四个名字位于文档不同地方并各自多次出现,怎样一次过把张三替换成李四,而李四替换成张三。同理,“王五”与“何六”互换。
谢谢mkw007! 展开
谢谢mkw007! 展开
4个回答
展开全部
要想自动化地一次过,采用VBA编程方式可以实现,编程思路是:
参考如下,你可以新建一个宏,将下列代码粘贴入该宏中,运行之后就可以圆满地实现你的目的了。设置了三个变量数组和一个循环变量,修改它们,可以实现其他目的。
代码如下:
=============================
Dim OriginalArr(1 To 4) As String '待查找的内容的数组,根据需要查找内容的数量,将4改变成相应的量即可
Dim ReplaceArr(1 To 4) As String '替换成的内容的数组,根据需要替换内容的数量,将4改变成相应的量即可
Dim TempString(1 To 4) As String '中间变量数组,根据需要替换内容的数量,将4改变成相应的量即可
Dim i As Integer
OriginalArr(1) = "张三" '内容可以根据需要自设置,其余同
OriginalArr(2) = "李四"
OriginalArr(3) = "王五"
OriginalArr(4) = "何六"
ReplaceArr(1) = "李四"
ReplaceArr(2) = "张三"
ReplaceArr(3) = "何六"
ReplaceArr(4) = "王五"
TempString(1) = "temp1"
TempString(2) = "temp2"
TempString(3) = "temp3"
TempString(4) = "temp4"
For i = 1 To 4 '根据数组OriginalArr的个数设置这里的循环变量的最大值
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = OriginalArr(i)
.Replacement.Text = TempString(i)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next i
For i = 1 To 4
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = TempString(i)
.Replacement.Text = ReplaceArr(i)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next i
============
参考如下,你可以新建一个宏,将下列代码粘贴入该宏中,运行之后就可以圆满地实现你的目的了。设置了三个变量数组和一个循环变量,修改它们,可以实现其他目的。
代码如下:
=============================
Dim OriginalArr(1 To 4) As String '待查找的内容的数组,根据需要查找内容的数量,将4改变成相应的量即可
Dim ReplaceArr(1 To 4) As String '替换成的内容的数组,根据需要替换内容的数量,将4改变成相应的量即可
Dim TempString(1 To 4) As String '中间变量数组,根据需要替换内容的数量,将4改变成相应的量即可
Dim i As Integer
OriginalArr(1) = "张三" '内容可以根据需要自设置,其余同
OriginalArr(2) = "李四"
OriginalArr(3) = "王五"
OriginalArr(4) = "何六"
ReplaceArr(1) = "李四"
ReplaceArr(2) = "张三"
ReplaceArr(3) = "何六"
ReplaceArr(4) = "王五"
TempString(1) = "temp1"
TempString(2) = "temp2"
TempString(3) = "temp3"
TempString(4) = "temp4"
For i = 1 To 4 '根据数组OriginalArr的个数设置这里的循环变量的最大值
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = OriginalArr(i)
.Replacement.Text = TempString(i)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next i
For i = 1 To 4
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = TempString(i)
.Replacement.Text = ReplaceArr(i)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next i
============
展开全部
呵呵 你把张三换成 春哥
再把李四换成张三,然后把春哥换成李四不就好了么
再把李四换成张三,然后把春哥换成李四不就好了么
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一楼的看二楼的回答撒、
把张三替换成英子再把李四换成张三
然后把英子换成李四也行撒
把张三替换成英子再把李四换成张三
然后把英子换成李四也行撒
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
点击工具栏上的“编辑”,点击“替换”,在“查找内容”栏写张三,在“替换为”栏上写李四,再点击“全部替换”即可~
555555555555555是我没看清状况……太惭愧了……………………
555555555555555是我没看清状况……太惭愧了……………………
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |