Articles  
 
[Printer-friendly version]
Creating Macros that Pause for User Input
By Gordon McComb

Pssst! Wanna make your macros really useful?

Get ’em to pause!

A common task for a macro is starting a document, and stopping mid-way through to wait for user input. You type some text, then tell the macro to continue.

In this column I’ll show you how to record a macro that pauses for user input. You will see that you can have your macro pause just once, or any number of times. You’ll also learn how to add a pause command to an already recorded macro.

Note: The following is for WordPerfect® for Windows version 7 (32-bit) through version 9.

Pausing for Effect: Creating a Fax Cover Sheet
A fax cover sheet makes an excellent example of recording a macro that pauses for user input. Though WordPerfect comes with several fax templates, recording your own lets you easily create a cover sheet just for you. Modifying one of the fax templates can be time-consuming whereas recording a macro just the way you want it takes very little time.

Begin by opening a new, blank document. Then follow these steps:
  1. Turn on macro recording by pressing CTRL + F10 (or choose Tools, Macro, Record).
  2. In the Macro Record dialog box, type FAXCOV in the Name box, and choose Record.
  3. Choose Layout, Font, and select 18 in the Font Size list, then choose OK.
  4. Press CTRL + B to turn on bold.
  5. Choose Layout, Line, Center. Type FAX COVER SHEET. Press CTRL + B to turn off bold.
  6. Press ENTER twice.
  7. Choose Format, Font, and select 12 in the Font Size list, then choose OK.
  8. Type Date:, and a space. Then choose Insert, Date/Time, Insert (if using Corel® WordPerfect® 7, choose Insert, Date, Date Text).
  9. Press ENTER twice.
  10. Type From:, and a space.
  11. Choose Tools, Macro, Pause. This places a checkmark beside the Pause command. Choose Tools, Macro, Pause again. This removes the checkmark.
  12. Press ENTER twice. Type To:, and a space. Repeat step 11.
  13. Press ENTER twice. Type Subject:, and a space. Repeat step11.
  14. Press ENTER twice. Type Number of pages:, and a space. Repeat step 11.
  15. Press ENTER twice.
  16. Turn off macro recording by pressing CTRL + F10.
Playing the Fax Macro
Test the macro by closing the current document without saving it. Open a new blank document. Play the macro by pressing ALT + F10, typing FAXCOV, and choosing OK.

The macro types FAX COVER SHEET in big letters in the center of the page, then inserts the date. It also inserts To:, and stops for your input.
  1. Type the name the fax is to, and Press ENTER. Pressing ENTER “releases” the pause, and the macro continues.
  2. The macro inserts From:, and stops for your input. Type who the fax is from, and Press ENTER.
  3. The macro inserts Subject:, and stops for your input. Type what the fax is about, and Press ENTER.
  4. The macro inserts Number of pages:, and stops for your input. Type the number of pages in the fax, and Press ENTER.
The macro finishes by inserting two extra lines. The macro has now finished, and you can add a note to the fax cover sheet, or print it out.

Adding Pauses to LETOPEN.WCM
To insert the pause for the recipients name and address, change the macro so it contains the following:

Application (WordPerfect; "WordPerfect"; Default!; "EN")
CenterCurrentPage (State: On!)
DateText ()
HardReturn ()
HardReturn ()
PauseKey (Key: Enter!)
HardReturn ()
PauseKey (Key: Enter!)
HardReturn ()
PauseKey (Key: Enter!)
HardReturn ()
HardReturn ()
Type (Text: "Dear ")
PauseKey (Enter!)
Type (Text: ":")
HardReturn ()
HardReturn ()

Save the changes, and close the LETOPEN.WCM macro.

Viewing the Fax Macro
You can view the contents of the FAXCOV.WCM macro to see how WordPerfect recorded the commands. Open the macro file by choosing Tools, Macro, Edit, locating FAXCOV.WCM, and choosing OK.

Note that the pauses are recorded as PauseKey (Key: Enter!) commands. Every time you choose the Pause command from the macro pop-up menu, WordPerfect inserted the PauseKey command. When playing a macro, the PauseKey command pauses the macro and allows for user input.

The Enter! parameter indicates that the pause is released by pressing the ENTER key. As you will learn a bit later, you can specify a different key or action to un-pause the macro by changing the Enter! parameter.

Here’s how your FAXCOV.WCM should look:

Application (WordPerfect; "WordPerfect"; Default!; "EN")
FontSize (FontSize: 18.0p)
AttributeAppearanceToggle (Attrib: Bold!)
Center ()
Type (Text: "FAX COVER SHEET")
AttributeAppearanceToggle (Attrib: Bold!)
HardReturn ()
HardReturn ()
FontSize (FontSize: 12.0p)
Type (Text: "Date: ")
DateText ()
HardReturn ()
HardReturn ()
Type (Text: "From: ")
PauseKey (Key: Enter!)
HardReturn ()
HardReturn ()
Type (Text: "To: ")
PauseKey (Key: Enter!)
HardReturn ()
HardReturn ()
Type (Text: "Subject: ")
PauseKey (Key: Enter!)
HardReturn ()
HardReturn ()

Starting Letters using Macros and Pauses
Armed with the PauseKey command, you can add pauses to any macro, including macros you’ve already recorded. Let’s see exactly how this process works. In the following, you’ll create a macro for “opening” letters.

The macro is quite simple: it inserts the date, then pauses to let you type the recipient’s name and address. It then types Dear and waits for you to fill in the name.

The macro will be recorded without the pauses. The PauseKey command will be inserted later at critical points to allow the macro to pause and wait for user input.

To record the letter opener macro, start from a new, blank document. Then perform these steps:
  1. Press CTRL + F10 to start macro recording.
  2. At the Record Macro dialog box, type LETOPEN in the Name box, and choose Record.
  3. Center the text on the page by choosing Format, Page, Center. Choose Current Page, and choose OK.
  4. Choose Insert, Date/Time, Insert (if using WordPerfect 7, choose Insert, Date, Date Text). This inserts the current date.
  5. Press the ENTER key four times.
  6. Type Dear and a space.
  7. Press the ENTER key twice.
  8. Stop macro recording by pressing CTRL + F10.
Clear the document without saving it. Open the LETOPEN.WCM macro. The macro should contain the following commands.

Application (WordPerfect; "WordPerfect"; Default!; "EN")
CenterCurrentPage (State: On!)
DateText ()
HardReturn ()
HardReturn ()
HardReturn ()
HardReturn ()
Type (Text: "Dear ")
HardReturn ()
HardReturn ()

Playing the LETOPEN.WCM Macro
Play the LETOPEN.WCM macro to see how your modifications work. Start in a new, blank document. Then:
  1. Press ALT + F10 to display the Play Macro dialog box.
  2. Type LETOPEN in the Name box, and press Play.
  3. The LETOPEN.WCM macro starts. It begins by centering the page, typing the current date, and inserting two hard returns.
  4. Type the recipient’s name and address. You need to type a total of three lines. Press ENTER after each line. (The macro pauses three times to allow you to type all three lines.)
  5. At the third line, the macro inserts two hard returns, and types Dear. Type the salutation, and Press ENTER.
You may now type the remainder of the letter.

Using a Different Key/Action to Un-pause the Macro
The LETOPEN.WCM macro, described in the previous section, uses a series of three pauses to allow you to type the recipient’s name and address. You press the ENTER key each time to un-pause the macro.

This technique has a disadvantage: what if the address you want to type consists of a different number of lines? The solution: use a key or action other than ENTER to un-pause the macro. You can specify that any of the following releases the pause:

• Press the Cancel (ESC) key.
• Choose Close from the File menu.
• Type a specific character, such as A or z.

Let’s use the Cancel key method as an example. Open the LETOPEN.WCM macro. Make a copy of it by choosing File, Save As. Type LETOPEN1.WCM, and choose Save.

The original LETOPEN.WCM will be left untouched, and we’ll edit the new macro, LETOPEN1.WCM. Modify the macro so that it looks like the following:

Application (WordPerfect; "WordPerfect"; Default!; "EN")
CenterCurrentPage (State: On!)
DateText ()
HardReturn ()
HardReturn ()
PauseKey (Key: Cancel!)
HardReturn ()
HardReturn ()
Type (Text: "Dear ")
PauseKey (Key: Enter!)
Type (Text: ":")
HardReturn ()
HardReturn ()

Save the LETOPEN1.WCM macro, and close it. In a new, blank document, play the LETOPEN1.WCM macro by pressing ALT + F10, typing LETOPEN1, and choosing OK.

This time, enter as few or as many lines for the recipient’s address that you want.

When you are done, press the Cancel (ESC) key. The macro inserts the Dear text, and waits for you to type the salutation. As before, Press ENTER when you are done typing the salutation.

Instead of the PauseKey method, which allows for only a limited number of keys or actions you can use to un-pause a macro, you can use the PauseSet command to specify any of several dozen possible key choices.

PauseSet sets the key (or action) that un-pauses the macro. Along with PauseSet, you use the Pause command (which does the actual pausing).

My favorite keys for un-pausing macros are CTRL + ENTER and ALT + ENTER. These key combinations equate to a hard page break and an end-of-field merge command, respectively. You use the macro command for either of these two actions with PauseSet.

• To un-pause a macro with CTRL + ENTER, use PauseSet (Token: HardPageBreak).
• To un-pause a macro with ALT + ENTER, use PauseSet (Token: MergeEndField).

To test the CTRL + ENTER method, open the LETOPEN1.WCM macro file. Choose File, Save As, and resave the file as LETOPEN2.WCM.

Revise the macro so it looks like this:

Application (WordPerfect; "WordPerfect"; Default!; "EN")
CenterCurrentPage (On!)
DateText ()
HardReturn ()
HardReturn ()
PauseSet (Token: HardPageBreak)
Pause
HardReturn ()
HardReturn ()
Type (Text: "Dear ")
PauseKey (Key: Enter!)
Type (Text: ":")
HardReturn ()
HardReturn ()

Save the changes, and close the LETOPEN2.WCM macro file. In a new, blank document, play the macro by pressing ALT + F10, typing LETOPEN2, and choosing Play. At the first pause, type the recipient’s name and address.

When you are done, press CTRL + ENTER. This un-pauses the macro, and it continues as usual. Type the salutation, Press ENTER, and the macro finishes.

Telling the User What to Do When a Macro Is Paused
When a macro is paused, WordPerfect displays a very dim Macro Pause indicator in the status bar. It’s easy to miss this message, and assume the macro has finished. This can cause problems for users who may not be aware that the macro has been paused.

Even more trouble is brewing if you are using a key other than ENTER to un-pause the macro. The user may know the macro is paused, but may not know how to un-pause it!

It’s always a good idea to display a message, and perhaps even sound a beep, when pausing a macro. You can display your own, easier-to-spot message in the status bar. This is done with the MacroStatusPrompt command.

The MacroStatusPrompt command uses two parameters: the first parameter tells WordPerfect to display or hide the status bar message. The second parameter specifies the message you want to display. Here’s an example:

MacroStatusPrompt (State On!; Prompt: "This message appears on the status bar.")

To see how the MacroStatusPrompt command works, open the LETOPEN2.WCM macro file we just created. Choose File, Save As, and resave the file as LETOPEN3.WCM.

Change the macro so it looks like the following:

Application (WordPerfect; "WordPerfect"; Default!; "EN")
CenterCurrentPage (State: On!)
DateText ()
HardReturn ()
HardReturn ()
MacroStatusPrompt (On!; Prompt: "Type name/address; then press CTRL + ENTER")
Beep
PauseSet (Token: HardPageBreak)
Pause
HardReturn ()
HardReturn ()
Type (Text: "Dear ")
MacroStatusPrompt (State: On!; Prompt: "Type salutation; then Press ENTER")
Beep
PauseKey (Enter!)
Type (Text: ":")
HardReturn ()
HardReturn ()

Save the changes, and close the LETOPEN3.WCM macro file. In a new, blank document, play the macro by pressing ALT + F10, typing LETOPEN3, and choosing OK. The macro pauses to allow you to enter the recipient’s name and address. It also beeps at you to get your attention, and displays a message in the status bar.

At the first pause, type the recipient’s name and address. When you are done, press CTRL + ENTER. At the next pause, type the salutation, Press S, and the macro finishes.

You’ve now learned just about all there is to know about pausing in WordPerfect macros. Now if someone could figure out how to create a macro to get the whole world to pause—say, from Friday night to Monday morning so the weekend is as long we want—we’d have it made!
Gordon McComb is a writer and consultant specializing in macros for word processors. His latest books on WordPerfect macros can be fount at http://www.gmccomb.com/. He can be reached at gmccomb@gmccomb.com.

Disclaimer: The information provided on OfficeCommunity.com is not legal advice, but is intended to be general information related to business issues. Articles reflect the opinion of the author and do not imply sponsorship, endorsement or approval by Corel Corporation.



   
  WordPerfect®
  Corel™ Presentations®
  Quattro® Pro
  CorelCENTRAL™
  Paradox®
 
 



Copyright © 2003 Corel Corporation. All rights reserved.
Company and product names are trademarks or registered trademarks of their respective companies.