Macro for search and replace not working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have MS Word 2002. I am trying to create a macro with a search and replace
for Times New Roman size 12 to replace it with Courier New size 10. It works
when creating the macro, but not when I run the macro. And there is no
mention of either font in the VBA (edit). Any ideas?

Thanks,
brad
 
Ok, I found a solution. When changing font and size of font in a macro,
don't use search and replace. Instead highlight area and use "Format" and
then "Font" from the toolbar.
 
The macro recorder does not store the complete range of functions and often
produces rather bulky code. To add font information to a search, you will
have to add it manually eg

Sub ReplaceExample()
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
'**********************
.Text = ""
.Font.Name = "Times New Roman"
.Font.Size = "12"
.Replacement.Text = ""
.Replacement.Font.Name = "Courier New"
.Replacement.Font.Size = "10"
'**********************
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
End With
End Sub

http://www.gmayor.com/installing_macro.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Back
Top