Word文字突出显示颜色

时间:2016-08-30 14:25:11

标签: word-vba

以下vba代码会从word文档中删除所有“文本高亮颜色”,但我只想删除“粉红色高亮”,而忽略其他高亮颜色。亲爱的成员们,任何帮助都将不胜感激。谢谢。

Sub HighlightRemoveAllPink()

    Selection.Find.ClearFormatting
    Selection.Find.Highlight = wdColorPink
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Highlight = 0
    With Selection.Find
        .text = ""
        .Replacement.text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With

    Selection.Find.Execute Replace:=wdReplaceAll


End Sub

1 个答案:

答案 0 :(得分:0)

首先,Selection.Find.Highlight需要布尔值,所以:

Selection.Find.Highlight = True

要删除特定颜色,我使用了以下代码:

With Selection.Find
  .Highlight = True
  Do While (.Execute(Forward:=True) = True) = True
    If Selection.Range.HighlightColorIndex = wdColorPink Then
       Selection.Collapse direction:=wdCollapseEnd
    End If
  Loop
End With