A family of Microsoft word processing software products for creating web, email, and print documents.
Use Find/Replace with formatting and the Replacement.Highlight property instead of manually moving the Selection. For example, to remove highlight from all occurrences of .5 in 12‑pt font:
Sub RemoveHighlightFromPointFive()
With Selection.Find
.ClearFormatting
.Text = ".5" ' text to find
.Font.Size = 12 ' only 12-pt text
' Replacement: same text, no highlight
With .Replacement
.ClearFormatting
.Text = ".5" ' keep the .5
.Highlight = False ' remove highlight
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
End Sub
Key points:
- Do not use
Selection.MoveLeft/MoveRightorSelection.EscapeKeyhere. - Use
.Replacement.Text = ".5"so the text is not deleted. - Use
.Replacement.Highlight = Falseto remove highlight formatting from all matches.
If the goal is to remove highlight from all highlighted text (not just .5), use the documented pattern:
Sub RemoveAllHighlight()
Dim rngTemp As Range
Set rngTemp = ActiveDocument.Range(Start:=0, End:=0)
With rngTemp.Find
.ClearFormatting
.Highlight = True
With .Replacement
.ClearFormatting
.Highlight = False
End With
.Execute Replace:=wdReplaceAll, _
Forward:=True, FindText:="", ReplaceWith:="", Format:=True
End With
End Sub
References: