Microsoft 365 and Office | Word | For home | Windows
A family of Microsoft word processing software products for creating web, email, and print documents.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello from Steve
Where below please where would I put Font 12
Sub Left()
Dim rng As range
Dim innerRng As range
Set rng = ActiveDocument.Content
With rng.Find
.ClearFormatting
.Text = "L\([0-9]{1,}-[0-9]{1,}-[0-9]{1,}\)"
.MatchWholeWord = False
.Format = False
.Forward = True
.MatchWildcards = True
.Wrap = wdFindStop
Do While .Execute
If rng.Font.ColorIndex <> wdRed Then
Set innerRng = rng.Duplicate
innerRng.MoveStart wdCharacter, 2
innerRng.MoveEnd wdCharacter, -1
innerRng.Font.Color = wdColorBlue
innerRng.HighlightColorIndex = wdYellow
innerRng.Font.Bold = True
End If
If rng.Start >= ActiveDocument.Content.End Then Exit Do
rng.Collapse wdCollapseFound
Loop
End With
End Sub
A family of Microsoft word processing software products for creating web, email, and print documents.
AI answer
Add the font size setting to the same innerRng.Font block where bold and color are applied. For example:
Sub Left()
Dim rng As Range
Dim innerRng As Range
Set rng = ActiveDocument.Content
With rng.Find
.ClearFormatting
.Text = "L\([0-9]{1,}-[0-9]{1,}-[0-9]{1,}\)"
.MatchWholeWord = False
.Format = False
.Forward = True
.MatchWildcards = True
.Wrap = wdFindStop
Do While .Execute
If rng.Font.ColorIndex <> wdRed Then
Set innerRng = rng.Duplicate
innerRng.MoveStart wdCharacter, 2
innerRng.MoveEnd wdCharacter, -1
innerRng.Font.Color = wdColorBlue
innerRng.HighlightColorIndex = wdYellow
innerRng.Font.Bold = True
innerRng.Font.Size = 12 ' ← set font size 12 here
End If
If rng.Start >= ActiveDocument.Content.End Then Exit Do
rng.Collapse wdCollapseFound
Loop
End With
End Sub
This ensures only the found inner range is formatted as blue, bold, highlighted, and size 12.
References: