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
The below script is not doing color and bold.
What is required please.
Sub Test()
Selection.Find.ClearFormatting
With Selection.Find
.Text = " 0.0"
.Replacement.Text = " Test 0.0"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Font.Color = wdColorRed
Selection.Font.Bold = True
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
A family of Microsoft word processing software products for creating web, email, and print documents.
Move the formatting into the Find/Replacement operation and turn on .Format. For example:
Sub Test()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = " 0.0"
.Replacement.Text = " Test 0.0"
' Tell Word this is a formatted Find/Replace
.Format = True
' Set formatting to apply to the replacement text
With .Replacement.Font
.Color = wdColorRed
.Bold = True
End With
.Forward = True
.Wrap = wdFindContinue
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
End Sub
Key points:
Selection.Font.Color and Selection.Font.Bold only affect the current selection, not the text being replaced by Find.Execute..Replacement.Font and set .Format = True so that the Find/Replace operation applies the color and bold formatting to the replacement text.References: