查找 VBA 中的通配符
Wildcards in find VBA
我有下面的代码可以找到“<<”anychar“>>”之间的任何word/text,但有时只有“<<>>”文本。
如何编写通配符字符串来捕获“<<>>”?
Selection.Find.ClearFormatting
With Selection.Find
.Text = "\<\<*\>\>*"
.Replacement.Text = "?????"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchWildcards = True
End With
Selection.Find.Execute
例如:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "\<\<[!\<]@[\>]{1;2}"
.Replacement.Text = "?????"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
我有下面的代码可以找到“<<”anychar“>>”之间的任何word/text,但有时只有“<<>>”文本。
如何编写通配符字符串来捕获“<<>>”?
Selection.Find.ClearFormatting
With Selection.Find
.Text = "\<\<*\>\>*"
.Replacement.Text = "?????"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchWildcards = True
End With
Selection.Find.Execute
例如:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "\<\<[!\<]@[\>]{1;2}"
.Replacement.Text = "?????"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub