Understanding macro commands and syntax

To edit and write macros, you must understand the PerfectScript programming language and the principles of computer programming. For most users, recording macro commands is more efficient than typing commands into the macro. WordPerfect opens a new blank window with another macro bar. After you have recorded keystrokes or commands, WordPerfect returns to the macro you are editing and inserts the newly recorded commands.

When you create macros using the macro command browser, the macro commands appear in a separate document, numbered. The first line of the macro identifies the program and default language that it uses. The remainder of the macro performs the reported instructions.

For more information about macro commands, see “Using macro conventions and formatting macros.”

Understanding components of macro commands

Macro commands consist of four parts: a command name, parameters, enumerations, and separators. The table and example below display and describe these elements of syntax.

Macro command component
Command name
Indicates which feature the command activates. Some commands consist only of a command name, such as FileOpenDlg().
Provides more information about the command, such as which options of a feature are active. Parameters are always enclosed in parentheses; for example, Backup (State:On!).
Sets the value of a parameter (for example, State: On! or State: Off!). Enumerations always end with an exclamation point.
Marks the parameters in a command. Semicolons separate individual parameters; parentheses enclose a series of parameters; and braces enclose a series of repeating parameters.

For example:

  MakeItFit (TargetPage:1;{Adjust: FitLeftMargin!};{Adjust:   FitLineSpacing!})   

The command in the above example has two parameters: TargetPage and Adjust. They are separated by a semicolon. Adjust is a repeating parameter with two enumerations specified: FitLeftMargin and FitLineSpacing. All the Adjust parameters are enclosed in braces to group them.

When you create macros using the macro command browser, the commands are inserted in the correct format. If you type a macro without the macro command browser, you must arrange macro commands and their elements in a precise order or syntax. Each macro command must be spelled correctly and must include all the required parameters and separators.

Using types of macro commands

There are three types of macro commands: product commands, OLE object commands, and programming commands. Product commands are specific to a product, such as WordPerfect or Quattro Pro. OLE object commands perform tasks on an OLE object. Programming commands work across applications; they are PerfectScript commands.

Command names often describe an action, such as Font, MarginLeft, Advance, and FootnoteOption, in WordPerfect; AlignObjectsLeft, BitmapBlur, SelectAllObjects, and ToolbarCopy in Presentations; or Range in Microsoft Excel. Command names are not case sensitive and usually do not contain spaces. Exceptions include programming commands that call a subroutine, such as Case Call or OnCancel Call.

A macro can use more than one application product and OLE object. Commands to the non-default application or OLE object require a prefix, which is specified in an application or object statement. For example,

  A1.AboutDlg ()   

A1 (followed by a period) is the prefix. It tells the compiler to use the application or Object assigned A1 in a PerfectScript application or Object statement.

Understanding syntax

Syntax refers to the grammatical rules that govern the form of macro statements and expressions. For example, the syntax of the following statement, which types “John Doe,” is correct:

  Type(Text: "John Doe")   

The syntax of the next example is incorrect and produces an error message because the statement lacks a closing parenthesis:

  Type(Text: "John Doe"   

If you find it difficult to distinguish different parts of a macro, remember that you can add extra line spaces, tabs, and even font changes to make the macro more readable. As long as the commands are written correctly, the macro compiler ignores extra spaces and lines.

Understanding macro commands and syntax