Share via

Word Replace All not functioning

SteveD 515 Reputation points
2026-02-04T20:51:04.57+00:00

Hello from Steve

Replace All not functioning

What is required please for the below script to function

Sub Test()

Selection.Find.Replacement.ClearFormatting

With Selection.Find

    .Text = "$"

    .Replacement.Text = "$"

    .Forward = True

    .Wrap = wdFindContinue

    .Format = True

    .MatchCase = False

    .MatchWholeWord = False

    .MatchWildcards = False

    .MatchSoundsLike = False

    .MatchAllWordForms = False

End With

Selection.Find.Execute

With Selection.Find.Font

    .Size = 14.5

    .Bold = True

    .Color = 12611584

End With

Selection.MoveDown Unit:=wdLine, Count:=1

Selection.Find.Execute Replace:=wdReplaceAll

End Sub

Microsoft 365 and Office | Word | For home | Windows
0 comments No comments

2 answers

Sort by: Most helpful
  1. Marcin Policht 91,060 Reputation points MVP Volunteer Moderator
    2026-02-04T21:02:07.54+00:00

    Looks like this is not working because you are changing the Find.Font after running an initial .Execute, and you are never defining the Replacement formatting. ReplaceAll applies whatever is configured in .Replacement, not what you set on Find.Font. You also do not need to run a first .Execute or move the selection. Configure everything first, including .Replacement.Font, then run one ReplaceAll.

    Try this structure instead:

    Sub Test()
    
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    
    With Selection.Find
        .Text = "$"
        .Replacement.Text = "$"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    
        .Replacement.Font.Size = 14.5
        .Replacement.Font.Bold = True
        .Replacement.Font.Color = 12611584
    
        .Execute Replace:=wdReplaceAll
    End With
    
    End Sub
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    Was this answer helpful?

    1 person found this answer helpful.

  2. SteveD 515 Reputation points
    2026-02-05T20:21:19.4466667+00:00

    Hello MarcinI have done what you asked meaning accept answer

    When I tap the accept answer it changes it to Unaccept answer.

    Steve

    Was 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.