I'm writing a macro in Word to remove the highlighting from all hyperlinks highlighted with wdGray25
. The search for all hyperlinks is done by
For Each oLink In ActiveDocument.Hyperlinks
If oLink.Range.HighlightColorIndex = wdGray25 Then
oLink.Range.HighlightColorIndex = wdNoHighlight
End If
Next oLink
The problem is that highlighting from some hyperlinks highlighted with wdGray25
is not removed. By examining hyperlinks with Alt+f9 it appears that wdGray25
highlighting isn't removed from those hyperlinks whose hyperlink/field (revealed only by Alt+f9) isn't highlighted. These hyperlinks seem normally highlighted when hyperlink/field is hidden. For these hyperlinks Range.HighlightColorIndex
returns 9999999.
How can I rewrite the code so that wdGray25
hyperlinks are found even though hyperlink/field isn't highlighted?
Find and replace specific formatting
You can search for and replace or remove character formatting in your document. For example, you can search for a specific word or phrase and change the font color, or you can search for specific formatting, such as bold or highlight, and change it.
If you don't see the Format button, click More.
To search for text with specific formatting, type the text in the Find what box. To find formatting only, leave the box blank.
Click Format, and then select the formats that you want to find and replace. For example, to find highlighted text, click Format > Highlight; to find bold text, click Format > Font, and then in the Find Font dialog box, select Bold in the Font style list.
Click the Replace with box, click Format, and then select the replacement formats as described in step 4.
(Source)
Also see: How to Remove or turn off hyperlinks
you could exploit the knowledge that those "hidden" hyperlinks have 9999999 as
HighlightColorIndex
property