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

Re: How to change the font for specific words? by Jay

Jay
Tue Apr 01 19:48:46 PDT 2008

On Tue, 01 Apr 2008 16:01:14 -0400, Tom Kreutz <kreutz@princeton.edu> wrote:

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

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

Re: How to change the font for specific words? by Tom

Tom
Fri Apr 04 13:29:51 PDT 2008

Dear Jay,

Many thanks for all your help!

Tom


Jay Freedman wrote:
> On Tue, 01 Apr 2008 16:01:14 -0400, Tom Kreutz <kreutz@princeton.edu> wrote:
>
>> 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.
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.