我正在编写一个宏来删除除wdGray25(其HighlightColorIndex等于15)之外的Word文档中的所有高亮颜色。当宏进入用wdGray25突出显示的超链接时会出现问题,当Alt + F9显示时,超链接/字段不会突出显示。在那种情况下,Do While .Execute循环进入无限循环并且永不退出。
如何重写代码以便.Execute方法不会进入无限循环?感谢您的帮助。
color_array = Array("2", "3", "4", "5", "6", "7", "9", "10", "11", "12", "13", "14")
For Each color_number In color_array
With Selection
.HomeKey Unit:=wdStory
With Selection.Find
.Highlight = True
.Text = ""
Do While .Execute
If Selection.Range.HighlightColorIndex = color_number Then
Selection.Range.HighlightColorIndex = wdNoHighlight
Selection.Collapse wdCollapseEnd
End If
Loop
End With
End With
Next
答案 0 :(得分:0)
我们可以通过Hyperlink
集合中的每个Hyperlinks
循环**,而不是搜索:
Sub RemoveHighlightFromHyperlinks()
Dim a As Hyperlink
For Each a In ActiveDocument.Hyperlinks
If a.Range.HighlightColorIndex <> 15 Then a.Range.HighlightColorIndex = wdAuto
Next a
End Sub
它循环遍历文档中的所有超链接。如果HighlightColorIndex <> 15
,请删除HighlightColorIndex
(设置为wdAuto
。)