vbams-wordword-2007word-2003

Finding Uppercase Letters including small brackets ()


I want to Find Four UPPERCASE/CAPITAL Letters which must include small brackets ().

For example (ABCD)

Following code work fine with letters but it does not highlight brackets.

I think it is not finding brackets.

Sub FindUppercaseLetter()

    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "([A-Z][A-Z][A-Z][A-Z])"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .MatchWildcards = True
    End With
    Selection.Find.Execute
End Sub

This is the case:


Solution

  • Parentheses have special meaning and need to be escaped wth a slash:

    .Text = "\([A-Z][A-Z][A-Z][A-Z]\)"