Font change not recorded in Word 2002

B

Brainlop

I am just beginning to relearn VBA. The book that I am using suggests
recording a macro that changes selected text to Aril, 12 point bold.
When I record the macro with Word 2002, it has not picked up the fontname
change from the font list, nor the point size change from the drop-down
list.
It just picks up the toggling of the bold button.
Is this a bug or am I doing something wrong?
 
M

Mark Tangard

Hi Brainlop,

My guess is that (1) you used the toolbar to change the font
settings rather than the Format->Font dialog, and (2) your
text was already in Arial 12 but not bold, so it didn't
record the change in the font name or size. Is that correct?

The crux of the issue is that a macro tends to record *results*
rather than actions. Toolbar buttons are often shortcuts for
built-in dialogs, so recorded code that uses them won't always
work as expected. This is one good reason to *write* macros
rather than record them. (Had you used the Font dialog, other
problems would have surfaced, since that method records EVERY
parameter in the dialog, which isn't what you want either.)

This is how I would have written the macro:

With Selection.Font
.Name = "Arial"
.Size = 12
.Bold = True
End With

Note that this would handle all cases, even if the Selection
font was Arial (or 12 or bold or any combination) to begin with.

Unless this was a very very early lesson in the book and/or
something designed to demonstrate the perils of recorded code,
I have to say that based on this, I'm not impressed with the
book.
 
N

Nadia

Brainlop said:
I am just beginning to relearn VBA. The book that I am using suggests
recording a macro that changes selected text to Aril, 12 point bold.
When I record the macro with Word 2002, it has not picked up the fontname
change from the font list, nor the point size change from the drop-down
list.
It just picks up the toggling of the bold button.
Is this a bug or am I doing something wrong?

I've had a similiar problem! I recorded a macro whereby I replaced all
specific matching fonts with a different particular font. When I
examined the macro, I found out that it had not recorded any of my
Font selctions, only the opening of the box. And I'm also with Word
2002... So it may not be a bug, it's certainly an irritant.

Nadia
 
M

Mark Tangard

Nadia,

You need to read the complete thread before posting. I wrote
a detailed answer to Brainlop's question 12 hours ago. Look
for it between yours and his.

It's not a bug, it's a matter of understanding how poor a tool
the macro recorder is.
 
B

Brian Pollard

What is annoying is that the macro recorder does pick up the selection of a
font from the font list in Word 97 and Word 2000. So it is clear that Word
2002 is not backwards compatible with these previous levels of Word in this
respect.

I appreciate the code given by Mark Tangard and know that it is a relatively
trvial matter. I did fiind two work arounds using the macro recorder:
1. Use the Font dialog box - but this brings in a load of other properties
not needed
2. Select the option to 'keep track of formatting' and then pick up the font
change from the styles and formatting drop down list - but again this is far
from ideal. For some reason this is recorded.

What concerns me is what other actions does the macro recorder not record,
when you are trying to get a feel for the properties and methods to use in
your own code from using the macro recorder.

Brian Pollard
 
M

Mark Tangard

Brian,

The takehome lesson from anything you learn from the macro recorder
will always include the point that recording is not a good primary
way to learn to write macros. It can help you learn the properties
and methods, as you've found, but it's not even efficient at that.
More intensely educational is to write code *in* the editor paying
careful attention to the list of valid completions that pops up
whenever you type a period after a keyword ("Auto List Members" in
the editor options), and, to a lesser extent, the parameter list
that appear when you type a comma or space after a property or
method that takes parameters ("Auto Quick Info"). These are both
turned on by default. (Most people, me included, advise turning
OFF the cursed "Auto Syntax Check," to banish the annoying warnings
when you enter imperfect code. (The lines will turn red when you
move off them; that's enough alarm.)

Bottom line: I wouldn't spend your energy looking for workarounds
to make the recorder more useful; you'll just get frustrated.
Recording teaches you to program about as well as a bathtub teaches
you to swim. You need the open ocean to get anywhere.

--
Mark Tangard <[email protected]>, Microsoft Word MVP
Please reply only to the newsgroup, not by private mail.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters
 

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