in Macros

Macro Recording: The Basics

Over the next few weeks Editorium Update will explain how to record macros and use them to simplify repetitive editorial tasks in Microsoft Word. I'd like to thank subscribers Meg Cox, Allene Goforth, and Dan A. Wilson for suggesting this topic. I'm especially grateful to Dan, who is an editor's editor and Microsoft Word expert, for writing one of the articles with me. (Dan is the proprietor of The Editor's DeskTop, http://www.editorsdesktop.com/.) At Dan's suggestion, I'll start with the basics, get a little fancier next week, and then show you Dan's backbreaker of an example two weeks from now, so stay tuned. If you're a member of the Freelance email list who signed up for this series of articles, welcome! I hope you'll find the newsletter valuable enough to stay with us. If you've been reading the past newsletters on searching with wildcards, you'll want to look at our Readers Write column after the feature article for some additional information.

Macros--the mysterium tremendum, the sanctum sanctorum of Microsoft Word. Or, hey, just a great way to automate those mind-numbing, finger-breaking tasks you've been doing manually for so long. Recording a macro is like recording a song from the radio, only you're recording keystrokes instead of music. Here's the basic procedure:

1. Start the macro recorder (just like starting your tape recorder).

2. Do the stuff you want to record (such as typing text and running Word features).

3. Stop the macro recorder (just like stopping your tape recorder).

Well, shoot, that's not so hard.

Now let's take a simple but real (and useful) example. As you edit, you probably transpose characters a lot--I know I do. But it takes several keystrokes to do it:

1. Select the character you want to move. (Hold down SHIFT and press the RIGHT ARROW key.)

2. Cut the character. (Hold down CTRL and press X.)

3. Move to the place you want to put the character. (Press the LEFT ARROW key.)

4. Paste the character. (Hold down CTRL and press V.)

That's seven keystrokes altogether--keystrokes you do over and over, all of the time. Let's make life easier by recording them in a macro:

1. START THE MACRO RECORDER

a. Click the "Tools" menu.

b. Click "Macro."

c. Click "Record New Macro" (in older versions of Word, click the "Record" button).

d. Type a name for your macro (something like "TransposeCharacters") in the "Macro name" box. (You can't use spaces in a macro name.) If you're using our Editor's ToolKit or Editor's ToolKit Plus program, don't call the macro "TransposeCharacters," as our programs already use that name.

e. Under "Assign macro to," click the "Keyboard" button.

f. With your cursor in the "Press new shortcut key" box, press the function key or key combination you want to use to run the macro. I like function key 12 (F12) for this macro, but you can use CTRL + T (for "Transpose") or something else. Word will show you if the key or key combination is already assigned. If it is, you can try a different one or overwrite the current assignment. It's up to you. You may want to avoid combinations using the ALT key, which works with various letters to activate menu items and dialog controls. You can, however, use ALT + CTRL, ALT + SHIFT, or SHIFT + CTRL as part of your combination.

g. Click the "Assign" button.

h. Click the "Close" button. The macro recording toolbar will appear with two buttons--the first to stop recording and the second to pause recording if you need to. That means the macro recorder is now recording what you do.

2. DO THE STUFF YOU WANT TO RECORD

a. Select the character you want to move. (Hold down SHIFT and press the RIGHT ARROW key.)

b. Cut the character. (Hold down CTRL and press X.)

c. Move to the place you want to put the character. (Press the LEFT ARROW key.)

d. Paste the character. (Hold down CTRL and press V.)

Notice that this is the same procedure we used previously when we *weren't* recording a macro. In other words, we transposed the two characters just as we ordinarily would. Be careful not to use the cursor keys to move to a certain character before following this procedure. If you do, those keystrokes will become *part* of the procedure, and you'll end up recording all of those cursor movements. The idea is to record only the keystrokes you want the macro to do for you.

3. STOP THE MACRO RECORDER

a. Click the "Stop" button (the button with the blue square) on the macro recording toolbar to stop recording.

That's it! You've recorded a macro. Now let's play it back:

1. Put your cursor between two characters you want to transpose.

2. Click the "Tools" menu.

3. Click "Macro."

4. In Word 97 or later, click "Macros."

5. Click the name of your macro to select it.

6. Click the "Run" button. (If you wanted to delete your macro, you could press the "Delete" button instead.)

That's one way to play back your macro. But since you assigned a key combination to the macro, it's a lot easier to do it like this:

1. Put your cursor between two characters you want to transpose.

2. Press the function key or key combination you've assigned to run the macro.

Presto! The two characters will be transposed.

In a way, what you've just done is create a feature (Transpose Characters) that Microsoft Word didn't have before. Are you beginning to see the possibilities?

You can learn more about Editor's ToolKit and Editor's ToolKit Plus, which have lots of handy macros like this one, here:

http://www.editorium.com/14842.htm

http://www.editorium.com/14857.htm

_________________________________________

READERS WRITE

~~~~~~~~~~~~~~~~~~~~~~

Wildcard Inconsistency

~~~~~~~~~~~~~~~~~~~~~~

Allene Goforth (agoforth@Aros.Net) discovered an interesting inconsistency in how wildcards are handled from one version of Microsoft Word to another. She wrote:

I finally started working on the wildcards yesterday. Everything was progressing smoothly until I got to Gandhi. I typed in Ghandi Gahndi Ganhdi and then I tried to change those to Gandhi, using G[andh]{3}i but it can't even find the above string--let alone change them.

[Allene was referring to our newsletter of March 28, 2001, which you can read here: http://www.topica.com/lists/editorium/read/message.html?mid=1706069286.]

G[andh][andh][andh][andh]i worked as did G[andh]@i so what am I doing wrong?

I responded (after doing some testing):

The string you are using--

G[andh]{3}i

--works great in Word 95, which is the version of Word I ordinarily use.

However, as you've learned, in Word 2000 it doesn't work. Instead, you have to use this:

G[andh]{4}i

In other Words, the wildcards seem to work differently in different versions of Word.

In Word 95, {3} means "three *more* of the previous expression."

In Word 2000, {3} means "*three* of the previous expression." Or so it seems.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Finding ANSI Codes on a Macintosh

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Erika Buky (erikab@socrates.Berkeley.edu) found what seems to be a bug when searching for ANSI codes on a Macintosh. She wrote:

I've been reading the newsletters on wildcards with great interest and amazing my friends with my wizardry. I've noticed one problem, however, in trying to apply your clever solutions for transposing first names and last names in lists, and so on--things that require use of a code for a paragraph break.

[Erika was referring to our newsletter of April 18, 2001, which you can read here: http://www.topica.com/lists/editorium/read/message.html?mid=1706365638.]

I'm using Word 98 on a Mac (OS 8.1), and the code ^013 for a paragraph break seems to work only sporadically. When I'm doing searches like the one above, which requires this code at the end of the second search expression--^013([A-z]@) ([A-z]@)^013--the replace operation fails, I think because the paragraph break code is not recognized. (Word selects the first name, the space, and the first 2 letters of the second name, a string which meets the search criteria if you ignore the paragraph break code.)

Codes like ^09 for tabs are also treated inconsistently; sometimes I've had better luck dropping the initial zero.

Any idea why this might be so? Any possible solutions?

I responded:

I've just done some testing, and this seems to me to be a bug in Word. In both Word 98 and 2001 (on the Mac, of course), ^013 is recognized *unless* you specify that you're using wildcards. Then Word doesn't find the paragraph mark. Try searching for ^013 (or ^13) all by itself with the "Use wildcards" checkbox turned off and then on, and you'll see what I mean.

The Word 2001 documentation specifically says to use ^13 rather than ^p when using wildcards, but when you actually try it, it doesn't work. This is a real problem for Mac users, because it means there's no way to search for paragraph returns when using wildcards--unless you use a two-step operation. For example, with "Use wildcards" turned off, you could replace ^p with

^p

(the

being an arbitrary code) and then (with "Use wildcards" turned on) searching for

([A-z]@) ([A-z]@)

.

Thanks to Allene and Erika for their questions.