Word not functioning

SteveD 625 Reputation points
2026-07-13T03:29:42.9233333+00:00

Hello from Steve

Objective please

from this   96 MONROE

to this 00096 MONROE

to this 00096 MONROE
```Sub AddZeroBeforeTwoDigits()

```haskell
With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "  [0-9]{2} "
    ' Replace with 000 + the two digits
    .Replacement.Text = "000\1"
    ' Turn on formatting for the replacement
    .Format = True
    .Replacement.Font.Size = 12
    .Forward = True
    .Wrap = wdFindStop
    .MatchWildcards = True
End With
``` Selection.Find.Execute Replace:=wdReplaceOne

End Sub

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

Answer accepted by question author
Senthil kumar 2,500 Reputation points
2026-07-13T05:21:36.48+00:00

Hi @SteveD

attached the modified code. its working well. please check and give your feedback.

.Text = " [0-9]{2} " here is the problem.

With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = " ([0-9]{2}) "
    .Replacement.Text = "000\1"
    .Format = True
    .Replacement.Font.Size = 12
    .Forward = True
    .Wrap = wdFindStop
    .MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

Thanks.

Was this answer helpful?

1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

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.