With ActiveDocument.Content.Find
.ClearFormatting
Do While .Execute("[李四,张三,王二]{2}", , , 1, , , 1)
With .Parent
.Select
With Selection
If Selection.text Like "李四" Then
.Find.Execute "李四", , , 0, , , , , , "赵五", 2 ' 替换功能,可以省略!
.Font.Color = wdColorGreen
ElseIf Selection Like "张三" Then
.Find.Execute "张三", , , 1, , , , , , "钱六", 2
.Font.Color = wdColorRed
ElseIf Selection Like "王二" Then
.Find.Execute "王二", , , 1, , , , , , "孙七", 2
.Font.Color = wdColorBlue
End If
End With
.Collapse 0
End With
Loop
End With
Selection.HomeKey Unit:=wdStory
测试文本:
李四打电话给张三说:“张三儿,我是小磊,王二家停电了。”
李三打电话给张二说:“三儿,我是大磊,王四家停电了。”
供大家参考,不一定正确。 |