查找大写字母,包括小括号()

时间:2016-04-24 17:55:30

标签: vba ms-word word-vba word-2007 word-2003

我想要Find四个大写/大写字母,其中必须包含小括号()

例如(ABCD)

以下代码可以正常使用字母,但不会突出显示括号。

我认为没有找到括号。

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

情况就是这样:

1 个答案:

答案 0 :(得分:2)

括号具有特殊含义,需要用斜线进行转义:

Creating Two Courses
Adding 6 students to course 1
Adding 3 students to course 2




Number of students in Course 1: 6 Students are: 

1: Tom Servo
2: Joel Robinson
3: Mike Nelson
4: Pearl Forrester
5: TV's Frank
6: Zap Rowsdower
Number of students in Course 2: 3 Students are: 
1: Tom Servo
2: Crow T. Robot
3: Zap Rowsdowerdropping 2 students from course 1
dropping 1 student from course 2

Number of students in Course 1: 6 Students are: 

Number of students in Course 2: 3 Students are: 

clearing course 2 course 2

Number of students in Course 1: 6 Students are: 

Number of students in Course 2: 0 Students are: