PDA

View Full Version : how to change text font between the codes in entire word documnet



srini4547
07-19-2016, 10:14 AM
Hi Team,

can some one please help me how to change the font between the code in entire word document

eg: <sample>
hai aow are you
</sample>

my requirement is i want to change the Font to courierNew for the text between <sample> and </sample> codes in entire word document . irrespective of existing font

Thanks In advance

gmaxey
07-19-2016, 12:54 PM
Sub ScratchMacroKillFlags()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "(\<sample\>)(*)(\</sample\>)"
With .Replacement
.Text = "\2"
.Font.Name = "Courier New"
End With
.MatchWildcards = True
.Format = True
.Execute Replace:=wdReplaceAll
End With
lbl_Exit:
Exit Sub
End Sub
Sub ScratchMacroIIKeepFlags()
'A basic Word macro coded by Greg Maxey
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "(\<sample\>)(*)(\</sample\>)"
.MatchWildcards = True
.Format = True
While .Execute
oRng.MoveStart wdCharacter, 8
oRng.MoveEnd wdCharacter, -9
oRng.Font.Name = "Courier New"
oRng.Collapse wdCollapseEnd
Wend
End With
lbl_Exit:
Exit Sub
End Sub