Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2007

Tip: Looking for answers? Try searching our database.

Conditional macro to change font

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
minditservices@gmail.com - 12 Sep 2007 15:07 GMT
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.
Jonathan West - 12 Sep 2007 15:39 GMT
> Macro programmers -
>
[quoted text clipped - 7 lines]
>
> 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.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

m rafala - 12 Sep 2007 18:18 GMT
And in case you do want a macro for this, just follow Jonathan's advice
while using the macro recorder.

>> Macro programmers -
>>
[quoted text clipped - 17 lines]
>
> Repeat for each font you want to replace.
Graham Mayor - 13 Sep 2007 07:35 GMT
No - the macro recorder does not store formatting information relating to
the replace function.

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> And in case you do want a macro for this, just follow Jonathan's
> advice while using the macro recorder.
[quoted text clipped - 26 lines]
>> www.intelligentdocuments.co.uk
>> Please reply to the newsgroup
minditservices@gmail.com - 13 Sep 2007 03:16 GMT
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!
Graham Mayor - 13 Sep 2007 07:53 GMT
> 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

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

minditservices@gmail.com - 14 Sep 2007 00:07 GMT
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!
Graham Mayor - 14 Sep 2007 07:20 GMT
You are welcome :)

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

>> 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.
[quoted text clipped - 38 lines]
>
> should do the trick
minditservices@gmail.com - 25 Sep 2007 22:50 GMT
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
Russ - 07 Oct 2007 04:35 GMT
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

> 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.

>> I need a macro that changes fonts in a document from:
>> Goudy Old Style to Garamond
[quoted text clipped - 3 lines]
>> If there are other fonts in the document I want to leave them as is. I
>> am only concerned with the above 2 fonts.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Jonathan West - 13 Sep 2007 22:04 GMT
> 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!

In that case, you might find this article of interest.

Find & ReplaceAll on a batch of documents in the same folder
http://www.word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.