Recording Macros

R

Robert

On Wd2002 I am trying to record a macro which selects the
word containing the IP (using F8+F8) and changes its font
to give emphasis. The keypresses work perfectly on a dry
run, but those concerned with selecting the font fail to
record. All others record properly. Am I doing something
wrong?
Also, there seems to be confusion in Word Help as to
whether mousework can be recorded in a Macro. I have
tried both mousework and only keypresses, but neither
results in the font change being recorded.
After this, I want to produce a macro to emphasize a word
by displaying it white on blue background. Again, I know
the keypresses, but is it likely to record?
Any suggestions please? Many thanks.
 
J

Jay Freedman

Hi Robert,

My main suggestion would be to forget about the recorder as anything but a
way of getting hints about how to write reliable macros.

A proper macro to change the font of the word at the IP or an extended
selection would be something like this, which you would never get from the
recorder:

Sub Emphasize()
If Selection.Type = wdSelectionIP Then
Selection.Words(1).Font.NameAscii = "Arial Black"
Else
Selection.Font.NameAscii = "Arial Black"
End If
End Sub

Even better, though, would be to define a character style containing the
desired formatting, and apply that with either a keyboard shortcut or a
macro (similar to the one above, but with Selection.Words(1).Style =
"EmphasisStyle" or whatever you name the style). That way, if you change
your mind about the formatting, you can just change the style definition and
all the places that use it will change at once.
 

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