How to change the font for specific words?

T

Tom Kreutz

I'm trying to write a macro to find and change the formatting (e.g.
italic) of particular words. Recording my Replace procedure (which
itself functions properly) only saves ".Format = True" (see below); it
doesn't seem to indicate anywhere WHAT format choices I had made (e.g.
Italics).

Any ideas?

Many thanks in advance!

Tom Kreutz

With Selection.Find
.Text = "(SUBTOTAL)(*)^13"
.Replacement.Text = "\1\2^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
 
J

Jay Freedman

I'm trying to write a macro to find and change the formatting (e.g.
italic) of particular words. Recording my Replace procedure (which
itself functions properly) only saves ".Format = True" (see below); it
doesn't seem to indicate anywhere WHAT format choices I had made (e.g.
Italics).

Any ideas?

Many thanks in advance!

Tom Kreutz

With Selection.Find
.Text = "(SUBTOTAL)(*)^13"
.Replacement.Text = "\1\2^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

It's a bug in the recorder (see
http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm) that it
"forgets" to record the formatting.

If you're search for italic text, add the line

.Font.Italic = True

and if you want to replace it with not-italic format, add the line

.Replacement.Font.Italic = False

OTOH, if you're trying to make it italic, then switch the True and False to the
opposite statements.

Incidentally, this bug is finally fixed in Word 2007.
 
T

Tom Kreutz

Dear Jay,

Many thanks for all your help!

Tom


Jay said:
It's a bug in the recorder (see
http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm) that it
"forgets" to record the formatting.

If you're search for italic text, add the line

.Font.Italic = True

and if you want to replace it with not-italic format, add the line

.Replacement.Font.Italic = False

OTOH, if you're trying to make it italic, then switch the True and False to the
opposite statements.

Incidentally, this bug is finally fixed in Word 2007.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
 

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