Share via

Not doing color and bold

SteveD 145 Reputation points
2026-02-28T18:53:40.72+00:00

Hello from Steve

The below script is not doing color and bold.

What is required please.

Sub Test()

Selection.Find.ClearFormatting

With Selection.Find

    .Text = "          0.0"

    .Replacement.Text = "   Test  0.0"

    .Forward = True

    .Wrap = wdFindContinue

    .Format = False

    .MatchCase = False

    .MatchWholeWord = False

    .MatchWildcards = False

    .MatchSoundsLike = False

    .MatchAllWordForms = False

End With

Selection.Font.Color = wdColorRed

Selection.Font.Bold = True

Selection.Find.Execute Replace:=wdReplaceAll

End Sub

Microsoft 365 and Office | Word | For home | Windows
{count} votes

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2026-02-28T18:53:48.72+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Move the formatting into the Find/Replacement operation and turn on .Format. For example:

    Sub Test()
    
        With Selection.Find
            .ClearFormatting
            .Replacement.ClearFormatting
    
            .Text = "          0.0"
            .Replacement.Text = "   Test  0.0"
    
            ' Tell Word this is a formatted Find/Replace
            .Format = True
    
            ' Set formatting to apply to the replacement text
            With .Replacement.Font
                .Color = wdColorRed
                .Bold = True
            End With
    
            .Forward = True
            .Wrap = wdFindContinue
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
    
            .Execute Replace:=wdReplaceAll
        End With
    
    End Sub
    

    Key points:

    • Selection.Font.Color and Selection.Font.Bold only affect the current selection, not the text being replaced by Find.Execute.
    • Use .Replacement.Font and set .Format = True so that the Find/Replace operation applies the color and bold formatting to the replacement text.

    References:

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.