Making Life Easier with Macros
If you are one of our many readers who use a word processor regularly,
there will be certain routines that you find yourself repeating
over and over again. Any of these repetitive routines that involve
several steps could most likely benefit from being put into a macro.
Once the macro is created, you can perform the routine with a simple
key combination or by selecting the macro from a menu or toolbar.
The more complex the routine, the greater the benefit from the macro.
You probably knew this already but may have thought creating a macro
was too difficult. Its actually quite easy.
In essence, a macro is a shortcut. Creating one involves turning
on the macro recorder and then doing the routine that you want the
macro to do. Then, you turn the recorder off and save the macro.
The macro is now a command that will repeat all of the recorded
keystrokes and mouse clicks whenever you run it.
Some of the actions that lend themselves to useful macros include:
- Formatting of text, borders or backgrounds
- Insertion of tables, logos or other graphics into a document
- Compiling indexes or Tables of Contents with customized settings
- Changing settings that are buried deep in submenus or dialog
boxes
- Mail merges and other complex but repetitive tasks
There are many others as well, and some may be unique to your operation.
Anything you do that requires a series of steps is a candidate for
a macro, if you find yourself doing the same steps on multiple occasions.
Before we go step-by-step through creating a macro in Microsoft
Word, there is one little catch. The macro recorder will pick up
mouse clicks but not mouse movements, so you must use keyboard shortcuts
for moving the insertion point, selecting text, etc. With that warning
out of the way, lets create a macro for ending off a letter.
- Open an old letter document (or create a new one), and delete
everything after the end of the last paragraph of text. The cursor
should be sitting right there after the period of the last sentence.
- Go to the Tools menu and select Macro, and then Record a New
Macro. This will open the Record Macro dialog box shown here.
- Give the macro a name up to 80 characters long (we called ours
Ending). The name can include an underscore but no
spaces, and it can contain numbers but must start with a letter.
- You will probably want to store your macro in the default Normal
template (Normal.dot), but if not, change it. A description is
optional.
- Click the Keyboard icon to assign a keyboard shortcut to this
macro. This will open the Customize Keyboard window.
- Type the key shortcut you want. We used Alt+E, but it will tell
you if your choice is already in use for something else. Next,
click Assign, and then Close.
- A little toolbar pops up with two buttons: one to stop recording
and one to pause. At this point you are actually recording your
macro.
- Hit the Enter key twice and then type Sincerely,. Press the
Enter key three more times and type in your name.
- Click the Stop button on the macro toolbar. Your macro is now
finished and ready for use.
- To try it out, delete your work, so that the cursor is once
more at the end of the text. Press Alt+E (or whatever key combination
you chose) and you will see Word magically type in an ending to
your letter.
This shortcut for ending your letters will now be available in
any Word document that uses the Normal template.
If you dont want to save it, go to Tools Macro again
and select Macros from the submenu. Find your macro on the list,
select it and click Delete. Before you delete it though, you might
want to select Edit instead and you can see what a Visual Basic
script looks like. Thats what macros actually are, and if
you know how to script in Visual Basic you can do things with macros
that go far beyond just recording keystrokes.
Of course, this macro weve made is rather simplistic and
most of them will contain more steps, but the principles are the
same. Here are some tips that might help in the longer ones.
- Think through the steps required for the action you want to
do. It might even be worth doing a practice run before you start
recording anything, and pay particular attention to any steps
that involve mouse movements so you can figure out the keyboard
substitutes. This includes text selection, drag-and-drop, etc.
- If your document will be saved as an HTML web page rather than
a .doc file, macros must be created with the Microsoft Script
Editor rather than the keystroke recorder. Thats beyond
the scope of this tech tip, but we just wanted you to know.
- Notice if your macro must execute at a specific point in the
document. For instance in the macro we just did, we probably should
have begun by typing Ctrl+End to make sure the cursor was positioned
at the end of the text. As it is now, if the cursor is in the
middle of the text and you press Alt+E, guess where Sincerely
will appear?
- If you enter settings in a dialog box, the macro records all
of the settings, not just the ones you entered, and all of them
will be applied when you run the macro.
- If you change a toggle setting, the macro will toggle the setting
each time it runs, no matter which state its in to start
with. If youre not paying attention, this fact and the one
in #4 can sometimes give you surprising results.
That’s all for this week. It certainly isn’t everything there is
to know about macros, but it should give you a useful start.
Disclaimer - The Micro 2000 Tech Tip is a free service
providing information only. While we use reasonable care to see
that this information is correct, we do not guarantee it for accuracy,
completeness or fitness for a particular purpose. Micro 2000, Inc.
shall not be liable for damages of any kind in connection with the
use or misuse of this information.
|