I cannot refer to fonts when find while recording a macro. Help.

M

Macro Neophyte

I'm trying to replace all instances of a given character with the same
character in Times New Roman. This is straightforward using Word's find and
replace feature. I have to do this often for several characters, so I tried
writing a macro for it. Unfortunately, the macro recorder wouldn't save any
font specifications, thus it replaced all instances of the character in
question with itself, withouth changing the font. In other words, the macro
does nothing. Is there some way to make this work?
 
G

Graham Mayor

You will have to insert the extra commands manually - something along the
lines of

Sub ReplaceExample()

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
'**********************
.Text = ""
.Font.Name = "Arial"
.Font.Bold = True
.Font.Size = "12"

.Replacement.Text = ""
.Replacement.Font.Name = "Times New Roman"
.Replacement.Font.Size = "11"
.Replacement.Font.Italic = True
'**********************
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With
Selection.Find.Execute replace:=wdReplaceAll
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top