View Single Post
 
Old 04-07-2017, 11:33 AM
KeviM KeviM is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Apr 2017
Posts: 1
KeviM is on a distinguished road
Default Attempting to find text, select words before it, and format the entire selection

Hello all,

I've been trying unsuccessfully to search for a phrase, select 2 words before it, then italicize the text (including the phrase I searched for). The code I have below is entirely unsuccessful, and somehow just deletes "and Michael". Any suggestions?

Sub Macro2()

Selection.Find.ClearFormatting
With Selection.Find
.Text = "and Michael"
.Replacement.Text = "and Michael"
.Forward = True
.Wrap = wdFindStop
Do While .Execute() = True
Selection.TypeParagraph
Selection.MoveLeft Unit:=wdWord, Count:=2, Extend:=wdExtend
Selection.Find.Replacement.Font.Italic = True
Selection.Font.Bold = True
Selection.Collapse Direction:=wdCollapseEnd
Loop
End With
End Sub
Reply With Quote