![]() |
Chapter 6
|
In this chapter:
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. A fax cover sheet or a memo is a good example of a process where you might want the macro to complete most of the document for you, but still allow you to enter the From, To, and Subject lines.
In this chapter you will learn 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 that lacks the pausing instruction.
Creating a Fax Cover Sheet with Pauses
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 that come with WordPerfect can be time-consuming whereas recording a macro just the way you want it takes very little time.
Recording the Fax Macro
Begin by opening a new, blank document. Then follow these steps:
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.
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.
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 File, Open, locating FAXCOV.WCM (it's in your default macros directory), and choosing OK.
Here's how your FAXCOV.WCM should look. 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 later in this chapter, you can specify a different key or action to unpause the macro by changing the Enter! parameter.
FAXCOV.CM
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 ()
If you've been following along in this book from the first chapters, you've already been introduced to the majority of the other commands in this macro. Commands you have encountered before include Type, HardReturn, AttributeAppearanceToggle, and Application. Three new commands are FontSize, Center, and DateText. As usual, the function of these commands is largely self-explanatory.
Note
If you see a command in a recorded macro that you are unfamiliar with, and you wish to learn more about it, you can look it up in the Macro Commands Inserter. To do so, click the Commands button, and choose WordPerfect as the command type. Locate the command in the list, select it, then right-click on it. The online help for that command appears.
Creating a Letter Opener Macro and Adding 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 at critical points to allow the macro to pause and wait for user-input.
Recording the Letter Opener Macro
To record the basic letter opener macro, start from a new, blank document. Then,
Clear the document without saving it. Open the LETOPEN.WCM macro. The macro should contain the following commands (your macro won't include the numbers; they are shown here for references purposes only!).
LETOPEN.WCM
1. Application (WordPerfect; "WordPerfect"; Default!; "EN") 2. CenterCurrentPage (State: On!) 3. DateText () 4. HardReturn () 5. HardReturn () 6. HardReturn () 7. HardReturn () 8. Type (Text: "Dear ") 9. HardReturn () 10. HardReturn ()
The LETOPEN.WCM macro contains a command that's new to the discussion: CenterCurrentPage. The CenterCurrentPage command centers the current page. The command uses a parameter, in this case On!. As you might guess, you can turn off the page centering by specifying CenterCurrentPage (State: Off!).
Adding Pauses to LETOPEN.WCM
We'll add a number of pauses to the LETOPEN.WCM macro: a series of three pauses to allow you to type the letter recipient's name and address, and another pause to allow you to type the salutation.
Note
Of course, you could have recorded these pauses with the rest of the LETOPEN.WCM macro, but the main purpose of this example is to show you how to manually add pauses to already-recorded macros.
To insert the pause for the recipients name and address, add a blank line after line 5. Then type:
PauseKey (Key Enter!) HardReturn() PauseKey (Key: Enter!) HardReturn() PauseKey (Key: Enter!)
To insert the pause for the salutation, add a blank line after Type ("Dear "), and type the following lines:
PauseKey (Key: Enter!)
Let's make the letter opener macro even easier to use by providing the colon character after the salutation. Press Enter to add a new line, and type:
Type (":")
Your macro should now look like the following (again, without the line numbering, which is used here only for reference purposes). Choose File, Save As, and name this version of the macro LETOPEN0.WCM, to differentiate it from the original LETOPEN.
LETOPEN0.WCM
1. Application (WordPerfect; "WordPerfect"; Default!; "EN") 2. CenterCurrentPage (State: On!) 3. DateText () 6. PauseKey (Key: Enter!) 8. HardReturn () 9. PauseKey (Key: Enter!) 10. HardReturn () 11. PauseKey (Key: Enter!) 12. HardReturn () 13. HardReturn () 14. Type (Text: "Dear ") 15. PauseKey (Enter!) 16. Type (Text: ":") 17. HardReturn () 18. HardReturn ()
If, when you save the macro, WordPerfect warns you of a "syntax error," you made a mistake typing one
or more of the commands. Syntax errors are shown in a large message box. The syntax error will point you to the
general spot in the macro where the error is. However, the exact error may be a line or two before or after the
indicated problem. Carefully review your macro for mistakes, and try saving again.
Close the LETOPEN0.WCM macro after it has been successfully saved.
Playing the LETOPEN0.WCM Macro
Play the LETOPEN0.WCM macro to see how your modifications work. Start in a new, blank document. Then,
Santa Claus One North Pole Way North Pole, Earth 01234
Press Enter after each line. (The macro pauses three times to allow you to type all three lines. At the third line, the macro inserts two hard returns, and types Dear. Type the salutation, and press Enter.
The macro finishes by typing a colon, and two hard returns. You can now finish typing the rest of the letter.
Using a Different Key/Action to Unpause the Macro
The LETOPEN0.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 only two lines, or contains four or even five lines? One method might be to create different macros, each one with a varying number of pauses for typing the recipient's name. But a better method is to simply use a different key or action to unpause the macro.
Instead of using the Enter key to unpause the macro, you can specify that any of the following releases the pause:
The last two options, typing a specific character or pressing any printable key (a printable key is a key that prints a character), are unsuited for the task at hand. However, either of the first two methods -- pressing the Cancel key or choosing File, Close -- can be adopted for use in the LETOPEN.WCM macro. 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.
Delete lines 6 through 11 of the macro. In the place of these lines type the following:
PauseKey (Key: Cancel!)
The LETOPEN1.WCM macro should now look like this (of course, without the reference line numbers).
LETOPEN1.WCM
1. Application (WordPerfect; "WordPerfect"; Default!; "EN") 2. CenterCurrentPage (State: On!) 3. DateText () 4. HardReturn () 5. HardReturn () 6. PauseKey (Key: Cancel!) 7. HardReturn () 8. HardReturn () 9. Type (Text: "Dear ") 10. PauseKey (Key: Enter!) 11. Type (Text: ":") 12. HardReturn () 13. HardReturn ()
Save and compile 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 as you want. When you are done, press the Cancel (Esc) key. Notice how this unpauses the macro. 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.
Even More Key Choices
Personally, I dislike using the Cancel key as a macro un-pauser, as it is not very intuitive. Using PauseKey (Key: Close!) is an alternative, but it not as easy as simply pressing a single key. You must either choose File, Close, or press Ctrl+F4, to unpause the macro.
Instead of the PauseKey method, which allows for only a limited number of keys or actions you can use to unpause a macro, you can use the PauseSet command to specify any of dozens of possible key choices). PauseSet sets the key (or action) that unpauses the macro. Along with PauseSet you use the Pause command, which does the actual pausing.
My favorite keys for unpausing 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 test the Ctrl+Enter method, open the LETOPEN1.WCM macro file. Choose File, Save As, and resave the file as LETOPEN2.WCM. Replace line 6 of the macro with the following:
PauseSet (Token: HardPageBreak) Pause
The entire macro should look like:
LETOPEN2.WCM
1. Application (WordPerfect; "WordPerfect"; Default!; "EN") 2. CenterCurrentPage (On!) 3. DateText () 4. HardReturn () 5. HardReturn () 6. PauseSet (Token: HardPageBreak) 7. Pause 8. HardReturn () 9. HardReturn () 10. Type (Text: "Dear ") 11. PauseKey (Key: Enter!) 12. Type (Text: ":") 13. HardReturn () 14. 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 unpauses the macro, and it continues as usual. Type the salutation, press Enter, and the macro finishes.
Note
You can also use the PauseCommand as follows:
PauseCommand (Token: HardPageBreak)
It does the same thing as the PauseSet/Pause combination detailed above.
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 Application Bar (called the Status Bar in WordPerfect 7). 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 use a key other than Enter to unpause the macro. The user may know the macro is paused, but may not know how to unpause 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. Choose File, Save As, and resave the file as LETOPEN3.WCM. After line 5 of the macro add the following:
MacroStatusPrompt (State: On!;
Prompt: "Type recipient's name and address; press Ctrl+Enter when done")
Beep
And, following the Type ("Dear ") command, add:
MacroStatusPrompt (State: On!; Prompt: "Type salutation; press Enter when done")
Beep
When finished, the macro should look like this:
LETOPEN3.WCM
1. Application (WordPerfect; "WordPerfect"; Default!; "EN") 2. CenterCurrentPage (State: On!) 3. DateText () 4. HardReturn () 5. HardReturn () 6. MacroStatusPrompt (On!; Prompt: 7. "Type recipient's name/address; then press Ctrl+Enter") 8. Beep 9. PauseSet (Token: HardPageBreak) 10. Pause 11. HardReturn () 12. HardReturn () 13. Type (Text: "Dear ") 14. MacroStatusPrompt (State: On!; Prompt: "Type salutation; press Enter when done") 15. Beep 16. PauseKey (Enter!) 17. Type (Text: ":") 18. HardReturn () 19. 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 display 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 Enter, and the macro finishes.
Self-Test Quiz
Quiz for Chapter 6. See Appendix B for answers to this quiz.
1. To record a pause as part of a macro, you:
A. Choose the File, Close command.
B. Choose the Tools, Macro, Play command.
C. Choose the Tools, Macro, Pause command.
D. Choose the Tools, Macro, Pause command, twice in succession.
2. Recording a pause into a macro inserts the following macro command:
A. DateText ()
B. HardReturn ()
C. PauseKey (Key: Enter!)
D. Type (Text: "From: ")
3. To unpause a macro when using the PauseSet (Token: HardPageBreak) command, you press:
A. Cancel (Esc key)
B. Ctrl+Enter
C. Alt+Enter
D. Alt+F4
4. You can cause the macro to emit an audible "attention-getting" sound with what macro command:
A. Sound()
B. Beep
C. MacroStatusPrompt
D. Can't be done
5. True or false: The MacroStatusPrompt command is used to display a message in WordPerfect's Status Bar/Application Bar when running a macro.
6. Which of the following produces the same result as
PauseSet (Token: HardPageBreak)
Pause
A. Beep
B. PauseCommand (HardPageBreak)
C. PauseKey (Key: HardPageBreak)
D. Any of the above