Chapter 3
You can record macros in Corel WordPerfect, Corel Quattro Pro, or Corel Presentations. Recording a macro saves a series of keystrokes and/or mouse actions that you can play later. Recorded macros automate routine tasks, such as setting margins, displaying a dialog box for user input, or opening or closing a file.
See the online Help in each application for information about recording macros.
A command-based macro language records keystrokes and/or mouse actions as commands. It does not record the actual keystrokes. For example, to display the Line Height dialog box (Corel WordPerfect), choose Format < Line < Height. If you record these steps, your macro contains a product command named LineHeight.
A recorded macro includes only product commands. When you play a recorded macro, each action is played in recorded order.
A written macro can also include non-recordable statements that specify how a macro performs a task. The writer specifies the conditions for playing assignments, loops, and programming commands. Writing a macro provides greater flexibility to determine function than recording a macro. You can write a macro in Corel WordPerfect and play it in the application that it was written for.
Because you do not need to use a macro editor to create or edit Corel WordPerfect Suite macros, you can insert macro commands by typing them in a blank document in Corel WordPerfect. Some macro commands are not recordable, and need to be typed in or inserted using the Command Browser. When you save a macro, remember to give it a .WCM extension.
Recording and playing macros can speed up routine tasks, but the real power of macros is tapped when product commands are used together with programming commands. This combines the functionality of Corel WordPerfect Suite features with the customizing, decision making, and iterative capabilities of a programming language. Using programming commands also makes it possible to include the functionality of other applications.
You can type commands into a macro that is saved in a file or in a template.
If you want to improve the readability of a macro, you can format it so that it includes tabs, spaces, and even font or text appearance changes. Formatting the macro will not affect how it works. For example, Corel WordPerfect records the following macro in this format:
PosDocBotton()
Type(Text:˛Sincerely˛
HardReturn()
HardReturn()
HardReturn()
HardReturn()
Type(Text:˛Ms. Hannah Black˛)
HardReturn()
Type(Text:˛Vice President, Marketing˛)
However, if you type the commands yourself or edit the existing macro, you could format it however you want it. For example, you could format it as follows:
PosDocBotton()
Type(Text:˛Sincerely˛
HardReturn()
HardReturn()
HardReturn()
HardReturn()
Type(Text:˛Ms. Hannah Black˛)
HardReturn()
Type(Text:˛Vice President, Marketing˛)
When compiled, macros are saved as Corel WordPerfect files.
The Command Browser helps you to insert macro product and programming commands into your Corel WordPerfect Suite macros.
Product commands perform functions that let you use Corel WordPerfect Suite features in your macros. Many product commands require you to specify parameters and enumerations; these give the applications information about which options to select in dialog boxes and whether certain features (such as the Ruler) should be displayed or hidden. You can use the Command Browser to specify the commands quickly.
Online Help for each command in the Command Browser is available. Right-click a command to display the Help topic for the highlighted command.
Inserting Commands
The Command Browser lets you easily insert product or programming commands into a macro you are editing.
To insert commands using the Command Browser in Corel WordPerfect,
1 If the Macro toolbar isn’t already displayed, click Tools > Macro > Macro Toolbar or Tools >Template Macro or Template Macro Toolbar.
2 Click Commands.
3 Click the Command type drop-down list, then select the type of command you want to insert.
4 Select the command from the Commands list box. If the Parameters list box is blank, skip to step 7.
5 If the command you selected has parameters, select the parameters you want to use in the Parameters list box.
6 If the parameter has enumerations, the insertion point moves to the Enumerations list box when double clicking Parameters. Select the enumeration you want to use from the Enumerations list box. If the Enumerations list box is blank, skip to step 7.
7 The insertion point moves to the place in the macro command where you may need to type additional parameters or values. Type any additional parameters you need in the Command Edit text box.
8 Click Insert to insert the completed product or programming command into your macro.
9 Click Close to return to the document window.
Tips
Inserting Commands from Corel PerfectScript
You can also access the Command Browser within Corel PerfectScript. In Corel PerfectScript, you can record, play, compile, and convert macros for all Corel WordPerfect Suite applications. PerfectScript starts automatically when you record or play a macro from a Windows application that supports macros. If you play a macro for an application that is not running, PerfectScript automatically starts the application.
To start Corel PerfectScript, from the Windows Start Bar, click Corel WordPerfect Suite 8 < Tools <Corel PerfectScript. You can set PerfectScript options, including the default macro folder, editor, and extension by clicking Tools < Settings in Corel PerfectScript.
In machine (computer) language, every word is a binary numeral consisting of zeros and ones. For example, the first three letters of the alphabet in binary notation are 1000001, 1000010, and 1000011. The binary result of 4 + 5 is 1001. Because binary numerals are hard to work with, English-based programming languages (such as Basic, Pascal, and C) were created. Programs written with the help of an editor or word-processor are saved as source files. A compiler creates an object file, which is a copy of the source file translated into machine language. Computers can execute only object files.
Macro languages are similar to programming languages. Macros are written with an editor or word-processor and saved as a source file. The macro compiler creates an object, which it saves in a hidden area of the source file (the macro compiler does not create a separate object file). When you edit the source file, the object is destroyed. It is recreated each time the source file is compiled. A compiled source file (macro) contains instructions that are executed when you play the macro.
A macro compiler is used to compile or “translate” macros so that Corel WordPerfect Suite Applications can play them. Macros in Corel WordPerfect are compiled when you record, play, or save them, or when you click Save & Compile or Options < Close Macro on the Macro Edit feature bar.
Important: If you receive an error message while the macro is compiling, you can click Cancel Compilation to close the dialog box; or you can click Continue Compilation to check for other errors that may be in the macro. In either case, the macro won’t play; all errors must be corrected first. You can edit the macro to fix the errors.
Troubleshooting Macro Problems
The compiler is a useful tool for troubleshooting macro problems. If the compiler locates an error, a dialog box displays that contains general information about the problem. The macro compiler, however, can make only a “best guess” as to what the macro is actually designed to accomplish. As a result, errors given by the compiler sometimes direct you to the problem, rather than specifically identify the problem.
Also, the PerfectScript application has debugging features. See the PerfectScript application online Help.
Errors are sometimes created when you edit a macro. For example, if you typed Centr (Corel WordPerfect command) instead of Center, when you choose Save & Compile, a compile-time syntax error displays a syntax error message box.
The compiler does not recognize Centr, and guesses that it is a Label’s calling statement. When the compiler reaches the end of the file and does not find a corresponding Label, it displays a syntax error message.
The compiler stops and displays a message when it discovers a macro syntax error. The message contains information about the error and its location (the compiler makes a best guess and may not always be accurate). Choose Cancel Compilation to dismiss the message box, or choose Continue Compilation to test for other errors. You must correct all errors before a macro will compile correctly. If you choose to continue the compilation after an error is displayed, subsequent errors may be inaccurate. When correcting compilation errors, start at the beginning and first correct the errors which are obvious, leaving the others until later, as some of these errors may have been caused by an earlier error.
Common syntax errors are:
The compiler identifies syntax errors and suggests solutions for the writer to verify.
Run-time is the same as execution time. Run-time errors occur while the macro is playing. Referencing a variable that has not been assigned a value causes a run-time error. Run-time error messages identify errors that occur while the macro plays and show where errors occur.
Macros Included with Corel WordPerfect Suite
Some macros are included with Corel WordPerfect and Corel Presentations. Click Tools < Macro < Play in the application to list the macros and play one.
You can also see macros information in Help. To access Macros Help in Corel WordPerfect and Corel Presentations, click Help < Help Topics < Contents < double-click Macros < click Macro Programming. To access Corel Quattro Pro Macros Help, click Help < Help Topics < Contents < Macro Command Reference.
You can add Macros Help to a menu, toolbar, or keyboard.