Conditional macro to change font

M

minditservices

Macro programmers -

I need a macro that changes fonts in a document from:
Goudy Old Style to Garamond
-and-
Avenir 45 to Gill Sans MT

If there are other fonts in the document I want to leave them as is. I
am only concerned with the above 2 fonts.

Thanks in advance for your help.
 
J

Jonathan West

Macro programmers -

I need a macro that changes fonts in a document from:
Goudy Old Style to Garamond
-and-
Avenir 45 to Gill Sans MT

If there are other fonts in the document I want to leave them as is. I
am only concerned with the above 2 fonts.

Thanks in advance for your help.

You don't need a macro for this. Go to Edit, Replace. On the dialog that
appears, click More. Place the cursor in the Find What box, an click Format,
then Font. On the dialog that appears select the font you want to change
from, and click OK. Then position the cursor in the Replace With box, click
Format, Font, and select the font you want to change to. Make sure that both
the Find What and Replace With boxes have no text, then click Replace All.

Repeat for each font you want to replace.
 
M

m rafala

And in case you do want a macro for this, just follow Jonathan's advice
while using the macro recorder.
 
M

minditservices

Thanks a lot fellas. I do want a macro to do this because I need to do
it to a ton of documents and want to just push a macro button. Either
way it solves my problem.

Cheers!
 
G

Graham Mayor

No - the macro recorder does not store formatting information relating to
the replace function.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

Thanks a lot fellas. I do want a macro to do this because I need to do
it to a ton of documents and want to just push a macro button. Either
way it solves my problem.

Cheers!

Sub ReplaceExample()
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
'**********************
.Font.Name = "Goudy Old Style"
.Replacement.Font.Name = "Garamond"
'**********************
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.Execute replace:=wdReplaceAll
Selection.HomeKey Unit:=wdStory
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
'**********************
.Font.Name = "Avenir 45"
.Replacement.Font.Name = "Gill Sans MT"
'**********************
.Execute replace:=wdReplaceAll
End With
End With
End Sub


should do the trick

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

minditservices

I was about to post again because the font information is not stored
in the macro during find and replace. But Graham fixed my problem
before I even knew I had a problem. Well done Graham. I used your code
and it works perfectly.

Thanks again!
 
G

Graham Mayor

You are welcome :)

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

minditservices

Additional snafu. We ran in to a batch of documents that have text
boxes. The macro wont change fonts inside of the text boxes or within
the footer of documents. A little more help would be much appreciated.

Thanks
 
R

Russ

This article will help with the footers, etc.
http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm

With text boxes you need to loop through the objects and if they are text
boxes change their default font.name property. The following macro shows a
way to do that for the main story textboxes, but if you combine it with the
ReplaceAnywhere macro, you can change all the fonts.

Dim objShape As Shape
For Each objShape In ActiveDocument.Shapes 'only in main story
With objShape
If .Type = msoTextBox Then
With .TextFrame.TextRange.Font
If .Name = "Goudy Old Style" Then
.Name = "Garamond"
ElseIf Name = "Avenir 45" Then
.Name = "Gill Sans MT"
End If
End With
End If
End With
Next objShape
 

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