An implementation of Visual Basic that is built into Microsoft products.
Use a wildcard Find/Replace in VBA that looks for exactly four digits and replaces them with a leading zero plus the same four digits.
Example macro:
Sub AddZeroBeforeFourDigits()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "<[0-9]{4}>"
.Replacement.Text = "0\1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
End Sub
Explanation:
-
.Text = "<[0-9]{4}>"finds any whole word that is exactly four numerals (0–9). -
.Replacement.Text = "0\1"inserts a0in front of the found four-digit sequence. -
wdReplaceAllupdates all occurrences in the document.
Run this macro on the document to prepend a zero to every standalone four-digit number.
References: