PDA

View Full Version : Clear specific highlighting



peartneil
06-19-2017, 11:29 AM
I'm trying to get the following code to work to clear highlighting of a specific color. Not sure what I'm doing wrong for it to scan the entire document for all instances of the color highlighting and remove it:


Sub remove_highlight()
'
' remove_highlight Macro
'
'
Dim hiliRng As Range
Set hiliRng = ActiveDocument.Range
With hiliRng.Find
.Highlight = True
.Execute
If hiliRng.HighlightColorIndex = wdColorTan Then
hiliRng.HighlightColorIndex = wdNoHighlight
End If
End With
End Sub

gmaxey
06-19-2017, 01:01 PM
There is no such thing as wdColorTan as a highlight color index.


Sub remove_highlight()
'
' remove_highlight Macro
'
'
Dim hiliRng As Range
Set hiliRng = ActiveDocument.Range
With hiliRng.Find
.Highlight = True
While .Execute
MsgBox "Found highlight " & hiliRng.HighlightColorIndex
If hiliRng.HighlightColorIndex = wdColorTan Then
hiliRng.HighlightColorIndex = wdNoHighlight
End If
Wend
End With
End Sub

peartneil
06-20-2017, 06:46 AM
My post count is too low to post links, but reference the existence of wdColorTan here: msdn.microsoft[dot]com/en-us/library/bb237558(v=office.12).aspx

gmaxey
06-20-2017, 02:53 PM
I didn't say or even suggest that there was no such thing as a color constant wdColorTan. I said that there was no .hightlightcolorindex wdColorTan. Maybe your text is not highlighted but shaded instead.


Sub remove_TanShading()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = ""
.Format = True
.Font.Shading.BackgroundPatternColor = wdColorTan
While .Execute
If oRng.Font.Shading.BackgroundPatternColor = wdColorTan Then
oRng.Font.Shading.BackgroundPatternColor = wdColorAutomatic
oRng.Collapse wdCollapseEnd
End If
Wend
End With
End Sub