Objective is to remove highlight

SteveD 625 Reputation points
2026-03-20T03:21:26.3333333+00:00

Hello from Steve

Objective find .5 font 12 then unhighlight

. of .5 is not highlighted only 5

The below finds the first and selects the 5 and when the second and others found it deletes the rest.

What is required please to replace all the 5 with no highlight.

Sub test()

selection.Find.ClearFormatting

selection.Find.Font.Size = 12

With selection.Find

    .Text = ".5"

    .Replacement.Text = " "

    .Forward = True

    .Wrap = wdFindContinue

    .Format = True

    .MatchCase = False

    .MatchWholeWord = False

    .MatchWildcards = False

    .MatchSoundsLike = False

    .MatchAllWordForms = False

End With

selection.Find.Execute

selection.EscapeKey

selection.EscapeKey

selection.MoveLeft Unit:=wdCharacter, Count:=1

selection.MoveRight Unit:=wdCharacter, Count:=1

selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend

selection.Font.Color = wdColorAutomatic

Options.DefaultHighlightColorIndex = wdNoHighlight

selection.range.HighlightColorIndex = wdNoHighlight

selection.Find.Execute Replace:=wdReplaceAll

End Sub

Microsoft 365 and Office | Word | For home | Windows

Locked Question. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

1 answer

Sort by: Newest
  1. AI answer

    2026-03-20T03:21:37.9633333+00:00

    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/MoveRight or Selection.EscapeKey here.
    • Use .Replacement.Text = ".5" so the text is not deleted.
    • Use .Replacement.Highlight = False to 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:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

    1 person found this answer helpful.