Word macro to do single only

SteveD 745 Reputation points
2026-11-23T01:42:52.9566667+00:00

Hello from Steve

I would like please word macro to do single only

Sub Dollar_Colour_Red_Bold2()

Options.DefaultHighlightColorIndex = wdYellow

With Selection.Find

    .ClearFormatting

    .Font.Size = 12

    .Text = "($[0-9,]{1,})"

    .Forward = True

    .Wrap = wdFindContinue

    .Format = True

    .MatchCase = False

    .MatchWholeWord = False

    .MatchAllWordForms = False

    .MatchSoundsLike = False

    .MatchWildcards = True

    With .Replacement

        .ClearFormatting

        .Text = "\1"

        With .Font

            .Bold = True

            .Color = wdColorRed

        End With

        .Highlight = True

    End With

    .Execute Replace:=wdReplaceAll

End With

End Sub

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

Answer accepted by question author

AI answer

2026-11-23T01:43:35.8966667+00:00

Change wdReplaceAll to wdReplaceOne; Word will format only the first matching dollar amount encountered. wdReplaceOne means “replace the first occurrence,” whereas wdReplaceAll processes every occurrence.^1^

Sub Dollar_Colour_Red_Bold2()

    Options.DefaultHighlightColorIndex = wdYellow

    With Selection.Find
        .ClearFormatting
        .Font.Size = 12
        .Text = "($[0-9,]{1,})"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchWildcards = True

        With .Replacement
            .ClearFormatting
            .Text = "\1"
            .Font.Bold = True
            .Font.Color = wdColorRed
            .Highlight = True
        End With

        .Execute Replace:=wdReplaceOne
    End With

End Sub

Each time the macro runs, it finds and formats one occurrence. Because .Forward = True, it searches forward from the current selection; .Wrap = wdFindContinue allows the search to continue from the beginning after reaching the document’s end.^2^


References

  1. WdReplace enumeration (Word)
  2. Find.Execute method (Word)
AI-generated content may be incorrect. Read our transparency notes for more information.

Was this answer helpful?

2 people found this answer helpful.

0 additional answers

Sort by: Most 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.