请再作测试:
Sub 孤独一叶() Dim a%, fcount%, i%, replace0 As String Dim find0 As String, find1 As String, find2 As String Dim find4 As String, find3 As String, find5 As String Application.ScreenUpdating = False Debug.Print Timer With ActiveDocument.Content.Find find0 = "([0-9])([0-9]{3}.)" find1 = "(.[0-9]{3})([0-9])" find2 = "([0-9])([0-9]{3}[ ])" find3 = "([ ])([0-9]{3})([0-9])" find4 = "([0-9])([0-9]{3})([!0-9])" find5 = "( )([0-9]{3})([-—年])" replace0 = "\1 \2" .MatchWildcards = True For a = 0 To 5 Select Case a Case 0 .Execute findtext:=find0, replacewith:=replace0, Replace:=wdReplaceAll Case 1 .Execute findtext:=find1, replacewith:=replace0, Replace:=wdReplaceAll Case 2 Do While .Execute(findtext:=find2) = True '如果发现 .Execute findtext:=find2, replacewith:=replace0, Replace:=wdReplaceAll Loop Case 3 Do While .Execute(findtext:=find3) = True '如果发现 .Execute findtext:=find3, replacewith:="\1\2 \3", Replace:=wdReplaceAll Loop Case 4 Do While .Execute(findtext:=find4) = True '如果发现 .Execute findtext:=find4, replacewith:="\1 \2\3", Replace:=wdReplaceAll Loop Case 5 Do While .Execute(findtext:=find5) = True '如果发现 .Execute findtext:=find5, replacewith:="\2\3", Replace:=wdReplaceAll Loop End Select Next End With Application.ScreenUpdating = True Debug.Print Timer
End Sub |