|
Sub test3()
Dim rngContent As Range, aMatch As Object, rng As Range, dic As Object, m&, n&, ar(), i&
Application.ScreenUpdating = False
Set rngContent = ActiveDocument.Content
a = rngContent.Text
Set dic = CreateObject("Scripting.Dictionary")
With CreateObject("VBScript.RegExp")
.Pattern = "[a-zA-Z’]+"
.Global = True
For Each aMatch In .Execute(rngContent.Text)
m = aMatch.FirstIndex: n = aMatch.Length
Set rng = ActiveDocument.Range(rngContent.Start + m, rngContent.Start + m + n)
If Not dic.Exists(LCase(rng.Text)) Then
dic(LCase(rng.Text)) = ""
Else
r = r + 1
ReDim Preserve ar(1 To r)
Set ar(r) = rng
End If
Next
End With
If r Then
For i = 1 To UBound(ar)
ar(i).Delete
Next i
End If
Application.ScreenUpdating = True
End Sub |
评分
-
2
查看全部评分
-
|