|
楼主 |
发表于 2013-8-21 21:25
|
显示全部楼层
8. 四重查找替换,本代码主要是让喜欢查找替换的朋友做一个参考,并不是像上面代码一样直接拿来使用,作用就是逐渐缩小范围来查找,直至缩小四次。有兴趣的朋友可在word文档键入=rand(15,3)回车测试下。
Sub 四重查找()
Selection.HomeKey wdStory
'With Selection.Find
With ActiveDocument.Content.Find
.Text = "那只[!^13]@懒狗[!^13]@^13"
.MatchWildcards = 1
Do While .Execute
.Parent.Select
.Parent.Font.Color = wdColorBrightGreen
Dim S As Range, P As Range, R As Range
Set ss = Selection.Range
Set S = Selection.Range.Duplicate
With S.Find
.Text = "敏捷*那只"
.MatchWildcards = 1
Do While .Execute
If Not .Parent.InRange(ss) Then
Exit Do
Else
.Parent.Font.Color = wdColorBlue
End If
Debug.Print .Parent
Set P = .Parent.Duplicate
With P.Find
.Text = "棕毛*跃过"
.MatchWildcards = 1
Do While .Execute
If Not .Parent.InRange(ss) Then
Exit Do
Else
.Parent.Font.Color = wdColorPink
End If
Debug.Print .Parent
Set R = .Parent.Duplicate
With R.Find
.Text = "狐狸"
.MatchWildcards = 1
.Replacement.Font.Color = vbRed
.Execute , , , , , , , , , , 2
.Text = "狐"
.Replacement.Font.Size = 24
.Replacement.Font.Bold = 1
.Replacement.Font.Color = wdColorBlack
.Execute , , , , , , , , , , 2
End With
Loop
End With
Loop
End With
Loop
End With
End Sub
|
|