2

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:

0m3r
  • 12,286
  • 15
  • 35
  • 71
VBAbyMBA
  • 806
  • 2
  • 12
  • 30

1 Answers1

2

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

.Text = "\([A-Z][A-Z][A-Z][A-Z]\)"
Alex K.
  • 171,639
  • 30
  • 264
  • 288
  • works fine. but i need to know at start you add slash before bracket `\(`but at end after `\)` ? – VBAbyMBA Apr 24 '16 at 18:17
  • 1
    The syntax is *`slashX`* where `X` is the character to escape so `\(` escapes `(` and `\)` escapes `)` – Alex K. Apr 24 '16 at 18:18