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.ColorandSelection.Font.Boldonly affect the current selection, not the text being replaced byFind.Execute. - Use
.Replacement.Fontand set.Format = Trueso that the Find/Replace operation applies the color and bold formatting to the replacement text.
References: