Changing font of a selection.

B

Ben K. Bullock

How can I change the font of the selection? I want to find a selection of
text and change its font automatically I tried recording it with the macro
recorder, but it didn't record anything when I changed the font.

Thank you for any help with this question.
 
H

Helmut Weber

Hi Ben,

there is an article at http://word.mvps.org/FAQs/General/index.htm
on modifying recorded macros.
Unfortunately, the search function seems to be out of order.

In short, the macro recorder doesn't record all.

Have a look at this example,
though there are numerous other ways
with advantages and drawbacks,
some of which may not be obvious at first glance.


Sub Macro1()
Dim rDcm As Range
Selection.Collapse
Set rDcm = Selection.Range
With rDcm.Find
.Text = "brown"
If .Execute Then
rDcm.Font.Name = "Arial Black"
rDcm.Select
End If
End With
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
J

Jay Freedman

Ben said:
How can I change the font of the selection? I want to find a
selection of text and change its font automatically I tried recording
it with the macro recorder, but it didn't record anything when I
changed the font.

Thank you for any help with this question.

The recorder has a bug that prevents it from recording replacement of
formatting. See http://word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm
for how to fix the macro.

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