如何在Word文档中选择某种颜色的所有突出显示



我需要一次选择.docx文件中的所有绿色突出显示。我认为这是一个宏是必要的,但我不知道如何编译它。有人可以帮助我吗?

我找到了这段代码,但它在找到它们后会删除所有突出显示,而我只需要选择它们:

Sub Highlight()
Dim r As Range
Set r = ActiveDocument.Range
With r.Find
.Highlight = True
Do While .Execute(FindText:="", Forward:=True) = True
If r.HighlightColorIndex = wdBrightGreen Then
r.HighlightColorIndex = wdAuto
r.Collapse 0
End If
Loop
End With
End Sub

VBA世界中有很多不同的颜色索引。 您需要定义要使用的确切绿色。 这可能是一个不错的起点。

Sub DeleteYellowHighlight()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Highlight = True
While .Execute
If rDcm.Font.ColorIndex = 4 Then
rDcm.Select
End If
Wend
End With
End Sub

或。。。

Sub FindNextYellow()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.MatchWildcards = False
.Forward = True
.Wrap = wdFindContinue
.Highlight = True
Do
.Execute
Loop Until Selection.Range.Font.ColorIndex = 4 _
Or Not .Found
Selection.Range.Select
End With
End Sub

另外,请参阅此链接,了解您可以做什么以及可以在哪里做这种事情的一些想法。

https://www.excel-pratique.com/en/vba/colors

最新更新