以下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
答案 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