如何使用vba更改单词中的默认突出显示?

时间:2013-06-27 22:27:39

标签: vba ms-word word-vba highlighting

我正在编写一个子文章,用整个单词查找特定文本并突出显示它。问题是用户希望文本为灰色(wdGrey25)而不是默认的黄色。这是我的示例代码:

Public Sub HighlightStrings()

    Dim rng As Range
    Set rng = ActiveDocument.Range(Start:=0, End:=0)
    With rng.Find
        .Forward = True
        .Wrap = wdFindStop
        .MatchWholeWord = True

        .Text = "Claimant's name"
        .Replacement.Highlight = True
        .Execute Replace:=wdReplaceAll

        .Text = "date"
        .Replacement.Highlight = True
        .Execute Replace:=wdReplaceAll

        .Text = "he/she"
        .Replacement.Highlight = True
        .Execute Replace:=wdReplaceAll

        .Text = "describe incident"
        .Replacement.Highlight = True
        .Execute Replace:=wdReplaceAll

        .Text = "describe condition(s)"
        .Replacement.Highlight = True
        .Execute Replace:=wdReplaceAll

        .Text = "describe occupational disease"
        .Replacement.Highlight = True
        .Execute Replace:=wdReplaceAll

    End With

End Sub

到目前为止,与以前的版本一样,它可以完美地找到并突出显示而不会抛出对齐和定位,但高亮颜色对于我们的老用户来说太难以看清了。有人得到了修复吗?

提前致谢, -C§

1 个答案:

答案 0 :(得分:1)

这就是你要找的东西:

   Options.DefaultHighlightColorIndex = wdGrey25

您需要在代码的开头设置它。