Home > other >  Wildcards in find VBA
Wildcards in find VBA

Time:05-03

I have the code below that finds any word/text between "<<" anychar ">>" but sometimes only "<<>>" text comes.

How can I write the Wildcards stings to catch "<<>>" also?


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  

CodePudding user response:

For example:

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
  • Related