Classic Computer Magazine Archive COMPUTE! ISSUE 142 / JULY 1992 / PAGE 6

Programming your word processor. (includes related articles on macros and software packages)
by William Harrel

The word programming brings to mind never-ending lines of confusing and unforgiving computer code complete with bugs and a lot of trial and error. Who needs it? Let the programmers program. Just give me software that does what it's supposed to. Sound familiar? What many users fail to realize is that creating program code for a word processor is often no different from performing normal functions within the software. Wouldn't you like to format a letter complete with margins, date, heading, salutation, font style, and signature block--all with one keystroke? Or how about transposing words or paragraphs by merely pressing Alt-T? You can automate these and other routine tasks. It's easy, once you understand how to use your word processor's macro feature.

What's a Macro?

Put simply, a macro is a file containing recorded keystrokes and commands that your word processor can execute. Most word processors come with a macro recorder built in. Turning it on requires only a couple of keystrokes or mouse clicks. As with a high-speed tape recorder, everything you do until you turn off the macro recorder is saved. You can replay the keystrokes anytime you want.

Each of the three word processors discussed in this article--WordPerfect for DOS (WPDOS), WordPerfect for Windows (WPWin), and Word for Windows (WinWord)--handles macros a little differently. But the result is the same: You save time by automating repetitive tasks.

WPDOS lets you create one-keystroke-combination (Alt-letter) macros and one-word macros. The two Windows applications also let you assign macros to keystrokes, although they're a little more difficult. And you can place them on the Button Bar in WPWin and on the Toolbar in WinWord. To learn how, see "Mapping Menus and Keyboards."

Ten Handy Macros

The key to recording macros is to know exactly what you want them to do before you start. Know each step. I go through the process once or twice before invoking the macro recorder.

For practice in creating macros, here are ten popular, useful macros. Note that WPWin doesn't automatically assign macros to keystrokes. You must do that with Preferences; see "Mapping Menus and Keyboards."

Insert Today's Date

WPDOS. To start the macro recorder in WPDOS, press Ctrl-F10 (hold down the Ctrl key and press F10). Name (or define) the macro by pressing Alt-D. At the Description prompt, type Insert date and press Enter. The recorder will now record your keystrokes. Enter the date as you normally do in WPDOS: Press Shift-F5; then press 2. The date is entered. Press Enter twice to put a line between the date and the next text you type, and then press Ctrl-F10 to turn off the macro recorder.

You can now enter the date anytime by simply pressing Alt-D.

WPWin. To start the macro recorder in WPWin, click on the Macro menu; then click on Record. In the Filename field, type Date (WPWin automatically gives the file the default WCM macro extension). In the Descriptive Name field, type Insert date, and then click on OK. WPWin is now recording keystrokes and commands. (While the recorder is on, the mouse isn't available for selecting text and graphics.) Click on the Tools menu; then click on Date. Select Text from the submenu. Press Enter twice to place a blank line before the next text you type. Now turn off the macro recorder by clicking on the Macro menu and selecting Stop.

To run this macro now, select Play from the Macro menu, find the filename DATE.WCM in the Play Macro dialog box, and double-click on it (or select it and click on the Play button).

WinWord. To start the macro recorder in WinWord, select Record Macro from the Tools menu (version 2.0). Type Date in the Record Macro Name field, place the cursor in the Key field, and press Shift-Ctrl-Q (this assigns the macro to this keystroke combination). Type Insert date in the Description field and click on OK. WinWord is now recording your keystrokes. To enter the current date, select Date and Time from the Insert menu. Find the date format you want and double-click on it. The date is inserted. Press Enter twice to insert a blank line, and turn off the recorder by selecting Stop Recorder from the Tools menu.

To run this macro now, select Macro from the Tools menu, find the macro Date in the Macro Name list, and double-click on it.

Italicize a Word

To record this macro, you should have some text on your screen.

WPDOS. Begin by placing the cursor anywhere on the word you want to italicize. Start the macro recorder; then define the macro by pressing Alt-I. At the Description prompt, type Italicize a word and press Enter. The recorder is on. Press Ctrl-Right Arrow to move the cursor to the next word. Press F12 to turn on Block, and then press Ctrl-Left Arrow. The word you want to italicize is highlighted. Press Ctrl-F8 for Font, 2 for Appearance, and 4 for Italic. The word is italicized. Press Ctrl-Right Arrow to move the cursor to the next word, and then turn off the macro recorder (Ctrl-F10).

You can run this macro anytime by placing the cursor on a word and pressing Alt-I.

WPWin. Begin by placing the cursor anywhere on the word you want to italicize. Start the macro recorder; then type Italic in the Filename field. In the Descriptive Name field, type Italicize a word and click on OK. The recorder is on. Press Ctrl-Right Arrow to move the cursor to the next word, press F12 to turn on Select Mode, and then press Ctrl-Left Arrow. The word is highlighted. Press Ctrl-I. The word is italicized. Press Ctrl-Right Arrow to move the cursor to the next word, press F12 to turn off Select Mode, and then select Stop from the Macro menu to turn off the macro recorder.

WinWord. Begin by placing the cursor anywhere on the word you want to italicize. Start the macro recorder and then type ItalicWord in the Record Macro Name field. Place the cursor in the Key field and press the I key. In the Description field, type Italicize a word and then click on OK. The recorder is on, ready to record your keystrokes. Press Ctrl-Right Arrow to move the cursor to the next word. Press Shift-Left Arrow to select the word. The word is highlighted. Press Ctrl-I. The word is italicized. Press Right Arrow to move the cursor to the end of the word, and select Stop Recorder from the Tools menu.

Spell Check a Word

If you've ever typed a word and then wondered if it was spelled correctly, this macro makes checking it easy. Begin with some text on your page.

WPDOS. Place the cursor on or directly after the word to check. Start the macro recorder, and then press Alt-W to define the macro. Type Spell check a word at the Description prompt. Press Ctrl-F2 for Spell; then press 1 for Word. Remember to turn off the macro recorder (Ctrl-F10).

If the word is spelled correctly, the cursor will move to the next word. If it's incorrect, the word will be highlighted. Correct it as you normally would. Return to your document by pressing the Esc key.

WPWin. Place the cursor on or directly after the word you want to check. Start the macro recorder, and type Spel-word in the Filename field. Type Spell check a word in the Descriptive Name field, and click on OK. Press Ctrl-Right Arrow to move the cursor to the next word. Press F12 to turn on Select Mode, and then press Ctrl-Left Arrow. The word is highlighted. Click on Speller on the Button Bar (or select Speller from the Tools menu), click on Start, and then turn off the macro recorder.

If the word is spelled correctly, a Spell check completed box appears. If the word's incorrect, change it as you normally would in WPWin.

WinWord. WinWord doesn't allow you to access the Macro menu while the Spelling dialog box is open. You can create this macro, but it requires some fairly sophisticated programming. See "Editing Macros" below for information on modifying macros.

Transpose Two Words

Begin with some text on your screen.

WPDOS. Place the cursor on the first of the two words you want to transpose. Turn on the macro recorder, and then press Alt-T to define the macro. Type Transpose two words at the Description prompt and press Enter. Press Ctrl-Right Arrow to move to the next word. Press F12 to turn on Block; then press Ctrl-Left Arrow. The first word is selected. Press Ctrl-F4 for Move, enter 1 for Block, and then enter 1 for Move. The word is deleted. Now press Ctrl-Right Arrow and press Enter. Turn off the macro recorder.

When you run this macro, be sure to begin with the cursor on the first word you want to transpose.

WPWin. Place the cursor on the first of the two words you want to transpose. Turn on the macro recorder. Type Tpose-w in the Filename field, type Transpose two words in the Descriptive Name field, and then click on OK. Press Ctrl-Right Arrow to move to the next word, press F12 to turn on Block, and then press Ctrl-Left Arrow. The first word is selected. Click on Cut in the Edit menu (or on the Button Bar). The word is deleted. Press Ctrl-Right Arrow to place the cursor one space after the word you want to transpose. Select Paste from the Edit menu (or from the Button Bar) and turn off the macro recorder.

When you run this macro, be sure to begin with the cursor on the first word you want to transpose.

WinWord. Place the cursor on the first of the two words you want to transpose. Turn on the macro recorder. Type TransposeWords for the Record Macro Name. Press 2 in the Key field and type Transpose two words for the Description; then click on OK. Press Ctrl-Right Arrow to move to the next word and Shift-Ctrl-Left Arrow to select the word. Click on Cut in the Edit menu. The word is deleted. Press Ctrl-Right Arrow to place the cursor one space after the next word. Select Paste from the Edit menu; then turn off the macro recorder.

When you run this macro, be sure to begin with the cursor on the first word you want to transpose.

Count Words

Make sure you have some text on-screen before you start.

WPDOS. Start the macro recorder; then press Alt-C to define the macro. Type Count words at the Description prompt and press Enter. Press Ctrl-F2 for Spell and 6 for Count. When WordPerfect stops counting, turn off the macro recorder. Press Esc twice to return to your document.

WPWin. You don't need a macro to count words in WPWin. Simply select Word Count from the Tools menu.

WinWord. WinWord doesn't allow you to access the Macro menu while the Statistics dialog box is open. You can create this macro, but it requires some fairly sophisticated programming. See "Editing Macros" above for information on modifying macros.

Transpose Two Paragraphs

Make sure you have at least two paragraphs of text on your monitor.

WPDOS. Begin with the cursor anywhere in the first of the two paragraphs you want to transpose. Turn on the macro recorder; then press Alt-P to define the macro. At the Description prompt, type Transpose paragraphs and press Enter. Press Ctrl-F4 for Move, select 2 for Paragraph, and enter 1 for Move. The first paragraph is deleted. Press F2 for Search, and at the Srch prompt, press Enter to search for a hard return. Press F2 to start the search. The cursor is on the line beneath the second paragraph. Press Enter, and then turn off the macro recorder.

When you run this macro, make sure you place the cursor on the first of the two paragraphs.

WPWin. Begin with the cursor anywhere in the first of the two paragraphs you want to transpose. Turn on the macro recorder; type Tpose-p in the File-name field and Transpose paragraphs in the Descriptive Name field. Click on OK. Choose Select from the Edit menu and Paragraph from the submenu. Select Cut from the Edit menu. The first paragraph is deleted. Now select Search from the Edit menu. In the Search dialog box, click on the Codes button. Scroll through the list of codes and double-click on HRt; then click on Close. Click on Search. To insert the first paragraph, select Paste from the Edit menu (or the Button Bar). Turn off the macro recorder.

When you run this marco, make sure you place the cursor on the first paragraph.

WinWord. Begin with the cursor at the beginning of the first line (before the tab indention) in the first of the two paragraphs you want to transpose. Turn on the macro recorder; type TransposeParagraphs for the Macro Record Name and Transpose adjacent paragraphs for the Description. Press P in the Key field. Click on OK. Press Shift-Ctrl-Down Arrow to select the first paragraph. Choose Cut from the Edit menu (or the Toolbar). The first paragraph is deleted. Press Shift--Down Arrow to move to the next paragraph. To insert the first paragraph, select Paste from the Edit menu (or the Toolbar). Turn off the macro recorder.

When you run this macro, be sure to place the cursor at the beginning of the first line in the first of the two paragraphs you want to transpose.

Insert Bullet

You can make items in a list stand out from straight text if you set them up as a bulleted list with a hanging indent.

WPDOS. Begin with the cursor where you want to start a bulleted list. Start the macro recorder and press Alt-B to define the macro. Type Bullet at the Description prompt; then press Enter. Press Ctrl-V for Compose. At the Key= prompt, type 4,0 and press Enter. Press F4 for Indent, and stop the macro recorder.

WPWin. Begin with the cursor where you want to start a bulleted list. Start the macro recorder and type Bullet in the Filename field and Insert bullet in the Descriptive Name field. Click on OK. Press Ctrl-W for WordPerfect Characters. Type 4,0 in the Number field and click on Insert and then on Close. Select Paragraph from the Layout menu, and select Indent from the submenu. Stop the macro recorder.

WinWord. WinWord is shipped with a bullet macro on the Toolbar.

Letter Template

Begin with a new document screen. At the instruction Type return address, type in the following information:

Your Name, Title

Your Company

Your Company's Street Address

The City, State ZIP code

WPDOS. Start the macro recorder. Press Alt-L to define the macro, and type Letter template at the Description prompt. Press Enter. Press Shift-F8 for Format; select 2 for Page and 5 for Top/ Bottom margins. Type 1.75 (or the measurement for your stationery). Press Enter twice. Select 1 for Center Page and Y for Yes; then press Enter. Press 1 for Line, 3 for Justification, and 1 for Left. Then press Enter twice to return to the document screen.

To enter the current date, press Shift-F5, and then select 2 for Date. Press Enter twice to insert a blank line. Type Return address. Press Enter twice, and then type Dear. Press Ctrl-F10 to end the macro record. You're now ready to type the letter.

WPWin. Start the macro recorder. In the Filename field, type Letter. Type Letter template in the Descriptive Name field. Click on OK. Select Margins from the Layout menu, press Tab twice to move to Top, and type 1.75 (or the measurement for your stationery). Click on OK. Select Page from the Layout menu; then select Center Page from the submenu. Select Date from the Tools menu and select Text from the submenu. Press Enter twice to insert a blank space. Type Return address, press Enter twice, and type Dear. Turn off the recorder. You're now ready to begin typing the letter.

WinWord. WinWord is shipped with a very sophisticated letter-template macro. It is, in fact, an impressive example of the power of WordBasic, WinWord's macro language. Access the template by selecting New from the File menu and then double-clicking on Letter in the templates list. You can modify margins, fonts, and other settings as needed. Be sure to save the template after you've changed the settings.

Insert Text (Closing a Letter)

Begin with an empty screen or at the end of a letter you want to close. At the Type the signature block instruction in each procedure, follow these steps: Type Thanks for your time and consideration. Then press Enter. Type Sincerely, and press Enter 4 times. Then type in your name, title, and company.

WPDOS. Start the macro recorder, and then press Alt-E. Type End letter at the Description prompt and press Enter. Type the signature block. Stop the macro recorder.

WPWin. Start the macro recorder. Type Close in the Filename field and Close letter in the Descriptive Name field. Click on OK. Type the signature block, and stop the macro recorder.

WinWord. The letter template shipped with WinWord provides several letter-closing options.

Sign a Letter

For this macro, you need a scanned image of your signature. If you don't have a scanner, you can have your signature scanned at a desktop publishing service bureau for a nominal fee.

First, use your word processor's graphics import, placing, and sizing options to create a document that looks like the one in the following example.

WPDOS and WPWin users, save the file as SIGNBLOC.WP5. WinWord users, don't save the document; instead, go to the WinWord procedure below. WPWin users, record the macro at the end of a letter you want to sign.

WPDOS. Turn on the recorder. Press Alt-S to define the macro, type Sign letter at Description, and press Enter. Press Shift-10 for Retrieve; then type SIGNBLOC.WP5 (be sure to include path information, if applicable). Press Y to retrieve current document. Stop the recorder.

WPWin. Select Record from the Macro menu. Type Sign in the Filename field and Sign letter in the Descriptive Name field. Click on OK. Select Retrieve from the File menu; then type SIGNBLOC.WP5 for the Filename (be sure to include path information, if applicable). Click on OK; then click on Yes to retrieve current document. Stop the macro recorder.

WinWord. The most efficient way to insert data into a WinWord document is with Glossary, an extension of WinWord's Merge feature. The procedure is simple: Select the data you want to include in the glossary, choose Glossary from the Edit menu, name the glossary, and then click on Define. Each time you want to use the data, insert a glossary bookmark using the Field option on the Insert menu.

This procedure is detailed in the WinWord manual. If you'd rather create a macro, the procedure is almost identical to the one in WPWin except that you'd name the signature block file SIGNBLOC.DOC and select File... from the Insert menu to retrieve it.

The Sky's the Limit

As macros go, these ten are simple. Once you get the hang of creating them, you're limited only by your ingenuity (and bravado). You can make them pause so you can type text and then restart them again, and you can create different versions of the same document based on different variables. The two for Windows even let you program dialog boxes that ask questions on how to proceed. Let your imagination be your guide.