突出显示Word 2013中的单词,但不区分大小写

时间:2013-08-14 14:40:21

标签: vba ms-word word-vba highlight

我正在尝试突出显示所有单词,但目前它是基于区分大小写的,我想避免这样做。

Sub Highlight_words()
    Dim range As range
    Dim i As Long
    Dim TargetList

    TargetList = Array("Array", "highlight", "With", "range", "matchcase")
        ' put list of terms to find here

    For i = 0 To UBound(TargetList)

        Set range = ActiveDocument.range

        With range.Find
            .Text = TargetList(i)
            .Format = True
            .MatchCase = True
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False

            Do While .Execute(Forward:=True) = True
                range.HighlightColorIndex = wdYellow
            Loop
        End With
    Next
End Sub

1 个答案:

答案 0 :(得分:2)

将.MatchCase = true更改为以下内容:

.MatchCase = False

干杯