![]() |
Chapter 4 Editing and Printing Your Macros |
Macros are regular WordPerfect for Windows documents, so you can use the full features of the program to open, edit, and print your macros, as you would any other kind of document. You might want to open and edit a macro that you've recorded so that you can add additional macro programming commands, or correct a mistake you made when recording the macro, or print the macro.
In this chapter you will learn how to open a macro you have recorded, view it, add to it, and print it. You will also learn how to add a description to the macro so that this description appears in the open file dialog box when the file is highlighted.
Recording a Sample Macro
Let's record a sample macro that can be later opened, edited, and printed. The macro is ITALSENT.WCM, for italicize sentence. It selects the current sentence, and formats it with italics. It finishes by turning the Select mode off.
Opening the ITALSENT.WCM Macro
Now that the ITALSENT.WCM macro has been created, you can open it. You can open macros in either of two ways:
Let's review both methods here.
Opening a Macro with File, Open
The most obvious way to open a macro file is to treat it like the regular WordPerfect document that it is. As with any document, choose File, Open. Move to the directory that contains your macros,. The default macros directory is specified in the File Preferences dialog box (choose Tools, Settings (or Edit, Preferences if using WordPerfect 7), then choose File, followed by Macros.)
Locate the macro file you wish to open, in this case ITALSENT.WCM. Choose Open. The macro file opens, and its contents show in the document window. The macro should look something like this.
ITALSENT.WCM
Application (WordPerfect; "WordPerfect"; Default!; "EN") SelectSentence () AttributeAppearanceToggle (Attrib: Italics!) SelectMode (State: Off!)
Note
Your macro doesn't look quite like the one above? That's okay. There may be some slight variations in the macro code you see in this book and the code your version of WordPerfect produces. This is especially true of the first line of the macro. You should be concerned only if your macro is significantly different than the sample shown. This note applies to the macro above, and any other macro described in this book.
Opening a Macro with Tools, Macro, Edit
Another way to open a macro for editing is to choose Tools, Macro, Edit. In the Edit Macro dialog box that appeas, type the name of the macro in the Name box -- in this case ITALSENT.WCM, and choose Edit. This method is generally easier than using the File, Open approach because the Edit Macro dialog box automatically displays the macros in the default macro path.
There is one difference between using File, Open and Tools, Macro, Edit: you can select and open more than one file (up to nine files open at a time) when using File, Open. With Tools, Macro, Edit, you can select and open only one file at a time.
Understanding the Macro Feature Bar
When you open a macro for editing WordPerfect displays the Macros Feature Bar (see Figure 4.1). As with other feature bars in WordPerfect, this one provides easy access to tools designed especially for macros. The individual buttons of the Macros Feature Bar is discussed in future chapters, starting with Chapter 5, "Important Macro Concepts."
For now, ignore the Macros Feature Bar if you open the macro file using the Edit command. We'll discuss its features as the topics come up throughout this book.
A Brief Discussion of the Innards of a Macro
The ITALSENT.WCM macro contains four lines. Each line is a separate command.
Application (WordPerfect; "WordPerfect"; Default!; "EN") SelectSeletence () AttributeAppearanceToggle (Attrib: Italics!) SelectMode (State: Off!)
For the purposes of this chapter, it is not important what the commands do, nor how they work. You can see
that most commands are self-explanatory, simply by their name. For example, the second line reads
SelectSentence()
It doesn't take a rocket scientist to figure out this command selects the current sentence. The same applies for the third and fourth line, which applies italics to the selected sentence, then turns select mode off.
The first line of ITALSENT.WCM is common to all macros you record. It specifies WordPerfect as the application that created the command. The "EN" ("US" if you're using WordPerfect 7) part of the command may not apply to you if you have a different language version of WordPerfect. For example, if you have the UK-English version of WordPerfect, the "EN" is replaced by a "UK." The two-letter language identifiers can be reviewed by choosing Tools, Language.
The final two lines of the ITALSENT.WCM macro are fairly self-explanatory, too. The AttributeAppearanceToggle command turns the specified character formatting (in this case italics) on or off. The SelectMode command turns select (F8 key) on or off. For both of these commands note the use of parentheses and special keywords inside the parentheses. We'll cover the meaning of these keywords in a future chapter, but suffice it to say, they are used to tell WordPerfect exactly how a particular macro command is to function.
AttributeAppearanceToggle (Attrib: Italics!)
SelectMode (State: Off!)
Watch Out For Mistakes!
Remember that a macro is a script for WordPerfect. It follows the script like an actor in a stage play. WordPerfect goes from one command to the next, performing whatever action the command says to do.
Because a macro is a script, you must be careful how you edit it. WordPerfect will stop and display an error if it encounters scripting instructions that it doesn't understand. For example, suppose you change the spelling of the SelectSentence command to SelectSent. WordPerfect knows what the command SelectSentence does, but not SelectSent. Macro playback will come to a grinding halt when WordPerfect encounters the SelectSent command.
The moral: know what you're doing when editing a macro, or else you may encounter all sorts of bizarre errors.
Adding a Comment to the Macro
If you plan on printing out your macros to make paper copies for future reference, one handy technique you can use is to insert the name of the macro at the top. On paper, you can review the contents of the macro, and instantly know the file where that macro is stored.
But you can't simply type the name of the macro, as doing so will confuse WordPerfect. When you play the macro, it will encounter the text of the name, and get confused. However, you can add a comment to the macro. The comment is ignored when the macro is played, but appears when you edit or print the macro.
Macro comments are different from the comments you use in WordPerfect documents (with the Insert, Comment command). A macro comment is simply a pair of slashes, followed by a line of text, like this:
// This is a comment.
You can add as many comments as you'd like in a macro. If the comment spans more than one line, keep it
under 256 characters, and don't press the Enter key to start a new line. To be on the safe side, if you write a
comment that spans several lines, insert the // characters in front of each line.
Let's practice adding a comment to the ITALSENT.WCM macro. Place the insertion point at the top of the macro, immediately before the Application command. Press Enter twice. Move back to the top of the macro and type the following two lines (don't forget the double slashes in front of each line!)
// italsent.wcm // Select current sentence, and italicize it
Note
You can make your macro "self-naming" by using the Filename feature of WordPerfect. Choose Insert, Other, Filename to insert the text of the current filename into the document. Again, be sure to add the two slashes so that WordPerfect knows this text is to be treated as a comment.
Saving Your Changes
Remember that macros are just like any other WordPerfect document. You must save any changes you make. As usual, to save choose File, Save. When saving a macro WordPerfect "re-compiles" it (the compiled version, stored in a hidden area of the document, is what WordPerfect uses when playing the macro). If you make a mistake in editing the macro, WordPerfect will display an error message box. Correct the error and try saving again.
You'll learn more about macro compiling in the next chapter.
Note
You can also press the Save & Compile button in the Macro Feature Bar to save the macro.
If you are done with the macro, you can close the file by choosing File, Close.
Printing a Macro
You can print your macros for future reference. Save the printed macros in a binder so you can easily access them. It's helpful to have a paper copy as you study the macro programming language in WordPerfect, and develop your own macros.
As you might imagine, you print macros in the same manner as you print any WordPerfect document.
Adding a Description to Your Macro
The more macros you develop, the more easily you'll lose track of what each one does. Despite your best intentions, will you be able to remember two or three months from now what the XTRREP.WCM macro does? Odds are you won't, unless you use the macro frequently enough that its purpose is permanently embossed in your frontal lobes.
A more pleasant way of remembering what your macros do is not to worry about remembering anything! Instead, have WordPerfect tell you precisely what the macro does. You can do this quite easily with the document summary feature of WordPerfect. While the file is open, you can place a description of the file into the document summary. Then, when you are scrolling through the list of macros files, you can view the descriptions at the bottom of the file dialog box.
To add a description to your macro.
Now, when using any file dialog box (choose File, Open, or click the directory button when in the Play Macro dialog box), you will see the description in the very bottom left corner of the dialog box as you highlight the macro file (see Figure 4.2). You should get into the habit of identifying all of your macros in this fashion.
Note
Don't see the description in the file dialog box? The likely reason is that "status bar" isn't displayed. Display the file dialog box status bar by first turning on menus in the file dialog box (click the little menu-shaped icon in the upper right corner). Then choose View, Status Bar.
Viewing Macros Without Opening Them
Sometimes, you just want to peek inside a macro to see what's in it. As with any other WordPerfect document, there is no need to actually open the file to see what's inside. Instead, highlight the file in the open file dialog box, then click the File Preview button. The contents of the macro file appears inside the View window.
You can view other macros simply by selecting another file in the file list. When you are done viewing the file, double click in the upper-right corner of the View window.
Viewing and Printing the "Shipping Macros"
WordPerfect for Windows comes with a number of macros. These are referred in the manual and on-line help as "shipping macros," because they ship with the product. The macros are normally placed in the default macro directory when you install WordPerfect. You should feel free to view, open, and print these macros.
Do bear in mind that many of the shipping macros are quite complicated in nature, and use advanced programming techniques. The shipping macro may look like Sanskrit to you now, but as you gain experience writing macros you will begin to understand the methods used in the shipping macros. Once you have learned the basics, you can study the shipping macros to learn macro programming techniques.
Self-Test Quiz
Quiz for Chapter 4. See Appendix B for answers to this quiz.
1. To open a macro for editing you may choose the following menu command (circle all that apply):
A. Edit, Go to
B. File, Open
C. Tools, Macro, Macro Toolbar
D. Tools, Macro, Edit
2. True or false: WordPerfect macros are really WordPerfect documents with macro code in them.
3. Comments can be added to a WordPerfect macro with the following:
A. The characters REM.
B. The characters // (two slashes).
C. The characters \\ (two back-slashes).
D. The ' (apostophe) character.
4. True or false: The Macro Feature Bar provides easy access to tools designed especially for macros.