Chapter 3


If you don't like the way a macro works after you create it, don't start over -- edit it. WordPerfect 5.1 has its own built-in editor where you can modify any macro. You can even create macros from scratch using the editor.

You'll learn the basics of editing macros in this chapter. You'll also discover how to reassign nearly any key on your computer to another function and how to create chained and nested macro while using the macro editor. The techniques you encounter in this chapter are used in the remainder of this book, and form the backbone of WordPerfect power macros.



The macro editor is almost an "invisible" feature of WordPerfect. You cannot access it unless you attempt to define an macro with a name that already exists. In that instance, WordPerfect prompts you that a macro with the name you have chosen already exists. You have four choices:

If you have yet to create a sample macro, you do make a "dummy" one that you can edit.

Key Sequence What it Does
1. [Ctrl]-[F10] Starts macro definition.
Names the macro TEST.
3. This is s a test [Enter] Describes the macro.
4. [Ctrl]-[F10] Ends macro definition.

Now, repeat steps 1 and 2, and at the prompt that appears press E or 2 to edit the macro. The macro editing window now appears. The contents of the macro is shown in the box. If you're editing a "dummy" macro (macro defined without any keystrokes), you'll see just a {DISPLAY OFF} code in the macro editor. If you're editing a macro that you've defined with keystrokes, you'll see all the keys you pressed.

To leave the editing window, press the [F7] to Exit. Upon exiting, the macro is automatically saved. If you want to leave the macro editor without saving any changes:

Key Sequence What it Does
1. [F1] Chooses Cancel key.
2. Y Answers Y, you do want to leave the editor without saving changes.

Macros that you've previously recorded appear with all the keystrokes you entered. Codes shown in boldface and in braces represent WordPerfect function or editing keys, such as {Screen} or {Bold}. In the editor, these function and editing codes are considered one character. You enter the codes by pressing the relevant key, and delete the entire code by pressing the [Backspace] or [Delete] key once. Alphabetic, numeric, and symbol keys appear in the macro editor window as single, unbolded characters.

Moving Within the Macro Editor

You move the cursor around within the macro editor box the same way as you do within WordPerfect's main document screen. Table 3-1 provides a quick run-down of the cursor movement keys, and what they do.

Table 3-1. Cursor Movement Within Macro Editor

To Press
Move to the beginning of the macro [Home], [Home], [Up]
Move to the end of the macro [Home], [Home], [Down]
Move to the top top of the box [Home], [Up]
Move to the bottom of the box [Home], [Down]
Move down one screen-full at a time [Page Down] Move up one screen-full at a time [Page Up]
Move to beginning of current line [Home], [Left]
Move to end of current line [End] or [Home], [Right]
Move right one word [Ctrl]-[Right]
Move left one word [Ctrl]-[Left]

Note that some of the standard WordPerfect cursor movements keys are not active within the macro editor. These are:

Using Function and Editing Keys

While working inside the macro editor, the standard editing keys -- such as [Backspace] and [Delete] -- function as they normally do in WordPerfect. Table 3-2 lists the editing keys you can use with the macro editor, and what they do.

Table 3-2. Function and Editing Keys in Macro Editor

To Press
Delete one character/code to left of cursor [Backspace]
Delete one character/code at the cursor [Delete]
Delete all characters/codes to the end of line [Ctrl]-[End]
Delete word at cursor [Ctrl]-[Backspace]

Standard WordPerfect editing keys you can't use in the macro editor are:

Inserting Editing Keys as Codes

If you want to place the definitions -- or codes -- of editing and cursor movement keys in the macro, do one of the following:

You use the [Ctrl]-V or [Ctrl]-[F10] keys to turn editing on and off for additional keys, as well. Table 3-3 lists those keys that must be used with either [Ctrl]-V or [Ctrl]-[F10] so the appropriate code can be entered into the editor.

Table 3-3. Keys that Need [Ctrl]-V to Add Key Code

Function Key
Cancel [F1]
Exit [F7]
Tab [Tab]
Enter [Enter]
Right cursor [Right]
Left cursor [Left]
Up cursor [Up]
Down cursor [Down]
Home [Home]
Typeover [Insert]
Delete [Delete]
Backspace [Backspace]
Page Up [Page Up]
Page Down [Page Down]
Screen Up - (on keypad)
Screen Down + (on keypad)
End [End]
Delete to end-of-line [Ctrl]-[End]
Delete to end-of-page [Ctrl]-[Page Down]
Delete Word [Ctrl]-[Backspace]
Word Left [Ctrl]-[Left]
Word Right [Ctrl]-[Right]
Goto [Ctrl]-[Home]
Escape [Esc]

The [Ctrl]-V sequence is used for entering two other types of macro codes, as well. These are:

The function of these codes is explained in Chapter 4, "Learning the Macro Programming Language."

Tip: If you press a key and WordPerfect responds differently, a modified keyboard layout may be currently in use. A keyboard layout redefines one or more of the keys on the keyboard. You might switch the functions of the Help and Cancel keys, for example, or modify the [Backspace] key so that it behaves differently than standard WordPerfect operation. In these instances, pressing a key may have a wildly different effect than you're expecting. If you think a keyboard layout is is the cause of your troubles, at the WordPerfect main editing screen choose the Setup key ([Shift]-[F1]), and note the entry beside the Keyboard Layout option. The currently active keyboard layout, if any, will be shown. You can quickly cancel any layout that's currently active by pressing [Ctrl]-6.

Prrogramming Codes

The macros you edit will most likely begin with a {DISPLAY OFF} code. If, when you defined the macro from the keyboard, you've turned the display off or on using the technique described in Chapter 2, "Adding Power to Macros," you may see additional {DISPLAY ON} and {DISPLAY OFF} codes. Too, pauses that you entered during macro definition will appear as {PAUSE}.

Codes that appear in all upper-case and within braces are WordPerfect's programming commands. {DISPLAY ON}, {DISPLAY OFF}, and {PAUSE} are just three of among 56 commands you can insert into a WordPerfect macro. While we'll discuss the macro programming language in detail in Chapter 4, you should know how these commands are added from within the macro editing window.

To insert a macro command, press the [Ctrl]-[Page Up] keys. A pop-up window appears over the macro editor box. You then use the cursor keys to select the command you want to insert, and press the [Enter] key when you're done.

Formatting the Macro Code

Note that pressing the [Tab] key tabs a line of macro code over approximately five spaces (two spaces at the beginning of the line), and that pressing the [Enter] key ends a line. The visual effect of these keys in the macro editing box does not relate to the operation of the macro. Adding four or five blank lines between segments of macro code does not produce four or five blank lines when the macro is executed.

You can "format" your macros for readability by adding Tabs and Enters as desired. The macro is now easier to read because you've separated its functions into logical units. When this macro is executed, the Tabs and Enters will not be included in the document.

Tip: Get into the habit of formatting your macros, especially if you plan to edit them or add additional program codes (as explained in Chapter 4). Develop a consistent style for macro formatting. Although adding Tabs and Enters for formatting purposes does increase the size of the macro by a small degree, the visual appeal and easy-of-use are well worth it.

To add [Tab] and [Enter] codes that are applied to the document during execution, enter them explicitly by first pressing either [Ctrl]-V or [Ctrl]-[F10].

Adding Comments to Macros

A technique often used by programmers is adding explanations or comments within their programmed code. You can do the same with WordPerfect macros. These comments don't execute when the macro is run, but they appear in the macro editor as a means to help you describe the workings of the macro, or to help you remember how you constructed a given macro.

To add a comment, press the [Ctrl]-[Page Up] key. If it isn't already, highlight the {;} Comment code, and press [Enter]. This inserts the {;} comment code in the macro. Write your comment, up to any length, and end it with a tilde (~) character. The tilde marks the end of the comment, and tells WordPerfect it that everything after this mark is to be executed.

Tip: You may wish to include comments when you are defining a macro from the keyboard. You do so using the same basic techniques as turning the display off and on or adding a pause, except that you choose the Comment option to insert a comment. Write the comment and press the [Enter] key when you're done.

Macro Editor Features

Other than adding and deleting pieces of macro code, the editor is very crude and lacks copy and paste editing features. The macro editor does not allow you to copy a segment of code from one part of the box and paste it into another. If you find you need to move a segment of code to another area of the macro, make a note of it and manually retype it. Double check that you have re-entered the code exactly as the original, then erase the original.

These capabilities are provided by Macro Editor 5.1, available separately from WordPerfect Corp. The Macro Editor, which is also included in the WordPerfect Library package, lets you edit macros created by all WordPerfect Corp. products. Note that the Macro Editor is version-sensitive; that is, you must use Macro Editor 5.1 with WordPerfect 5.1 Macro Editor 5.0 edits WordPerfect 5.0 macros only.

You can, however, include the text characters of a [Alt]-key macro by running the macro during editing. For example, suppose you are editing a macro for preparing a boilerplate customer reply letter. You have a large paragraph that you don't want to retype. Position the cursor in the editing box where you want the text to appear, then press [Alt] and the appropriate letter. The [Alt]-key macro executes, as normal, and its text is entered into the new customer reply macro.

Note that this technique only works with [Alt]-key macros. If the macro you want to use isn't an [Alt]-key macro, you can easily convert it simply by renaming it. You can use DOS or WordPerfect's List Files feature to rename a macro file.

IMPORTANT: WordPerfect will act "dead" if you try to load the contents of an [Alt]-key macro when that macro starts with a {DISPLAY OFF} code (WordPerfect automatically adds this code to all new macros it creates, but never adds the {DISPLAY ON} code at the end). You need to edit the [Alt]-key macro before you use it and remove the {DISPLAY OFF} code. If you forget to do this, press [F1] to cancel the operation and WordPerfect will come back to life.



The [Ctrl]-[Page Up] key is multi-faceted, and performs many duties, depending on what you're doing with WordPerfect at the time. There are four uses of [Ctrl]-[Page Up], some of which we have already covered.

  1. From the WordPerfect document editing screen: pressing [Ctrl]-[Page Up] allows you to assign values to variables. Variables are temporary holders of information (such as text or numbers) that you can retrieve later or use in a macro. Variables are detailed more fully in future chapters.
  2. When defining a macro: pressing [Ctrl]-[Page Up] lets you add a comment, add a pause, assign a value to a variable, or turn the display off and on.
  3. When in the macro editor: pressing [Ctrl]-[Page Up] accesses the macro programming commands.
  4. When in the macro editor: pressing [Ctrl]-V, then [Ctrl]-[Page Up] inserts a special {Macro Commands} code in the macro. This code has special use when working with variables or when creating macros that actually write other macros.



The macro editing window displays the meaning of the WordPerfect's function and editing keys as codes. Most codes are self-explanatory, but if you find a code that is new to you, look it up in Table 3-4.

Table 3-4. Macro Editor Codes and Corresponding Keys

Code Press Comments
{-} Alt-- Alt and minus key
{ } Special access; see  Chapter 19
{^\}       Special access; see  Chapter 19
{^_} Ctrl-\
{^A} Ctrl-A
{^B} Ctrl-B
{^C} Ctrl-C
{^D} Ctrl-D
{^E} Ctrl-E
{^F} Ctrl-F
{^G} Ctrl-G
{^M} Ctrl-M
{^N} Ctrl-N
{^O} Ctrl-O
{^P} Ctrl-P
{^Q} Ctrl-Q
{^R} Ctrl-R
{^S} Ctrl-S
{^T} Ctrl-T
{^U} Ctrl-U
{^V} Ctrl-V, Ctrl-V
{^]} Ctrl-]
{Alt-Home} Alt-Home
{Backspace} Ctrl-V, Backspace
{Block Copy} From macro command list
{Block Move} From macro command list
{Block Append} From macro command list
{Block} Alt-F4
{Bold} F6
{Cancel} Ctrl-V, F1
{Center} Shift-F6
{Columns/Tables} Alt-F7
{Compose} Special access; see Chapter 19
{Date/Outline} Shift-F5
{Del Word (Row)} Special access; see Chapter 19
{Del to EOP} Ctrl-V, Ctrl-Page Down   Also Ctrl-L
{Del to EOL} Ctrl-V, Ctrl-End     Also Ctrl-V, Ctrl-K
{Delete Word} Ctrl-V, Ctrl-Backspace
{Delete} Ctrl-V, Delete
{Down} Ctrl-V, Down Also Ctrl-Z
{End Field} F9
{End} Ctrl-V, End
{Enter} Ctrl-V, Enter Also Ctrl-V, Ctrl-J
{Escape} Ctrl-V, Esc Also Ctrl-V, Ctrl-[
{Exit} Ctrl-V, F7
{Flush Right} Alt-F6
{Font} Ctrl-F8
{Footnote} Ctrl-F7
{Format} Shift-F8
{Goto} Ctrl-V, Ctrl-Home
{Graphics} Alt-F9
{Hard Page} Ctrl-Enter
{Help} F3
{Home-Home-Left} Special access; see Chapter 19
{Home} Ctrl-H
{Indent} F4
{Invalid} Special access; see Chapter 19
{Item Left} Alt-Left
{Item Right} Alt-Right
{Item Up} Alt-Up
{Item Down} Alt-Down
{Keyboard} Special access; see  Chapter 19
{L/R Indent} Shift-F4
{Left Margin Rel} Shift-Tab
{Left Search} Shift-F2
{Left} Ctrl-V, Left Also Ctrl-Y
{List Files} F5
{Macro Define} Ctrl-V, Ctrl-F10 Code not active
{Macro} Alt-F10
{Mark Text} Alt-F5
{Menu Bar} Alt-= Alt and equals key
{Merge Codes} Shift-F9
{Merge/Sort} Ctrl-F9
{Move} Ctrl-F4
{Page Down} Ctrl-V, Page Down
{Page Up} Ctrl-V, Page Up
{Para Up} Ctrl-Up
{Para Down} Ctrl-Down
{Print} Shift-F7
{Replace} Alt-F2
{Retrieve} Shift-F10
{Reveal Codes} Alt-F3
{Right} Ctrl-V, Right Also Ctrl-X
{Save} F10
{Screen Down} Ctrl-V, Screen Down
{Screen Up} Ctrl-V, Screen Up
{Screen} Ctrl-F3
{Search} F2
{Setup} Shift-F1
{Shell} Ctrl-F1
{SHy} Ctrl-- Ctrl and minus key
{Spell} Ctrl-F2
{Style} Alt-F8
{Switch} Shift-F3
{Tab Align} Ctrl-F6
{Tab} Ctrl-V, Tab Also Ctrl-V, Ctrl-I
{Text In/Out} Ctrl-F5
{Thesaurus} Alt-F1
{Typeover} Ctrl-V, Insert
{Underline} F8
{Up} Ctrl-V, Up Also Ctrl-W
{Word Left} Ctrl-V, Ctrl-Left
{Word Right} Ctrl-V, Ctrl-Right

Additional Codes

Code Meaning
{COMMAND} Macro command code (from commands list)
{ALT x} Nested Alt-key macro
{VAR x} Numbered variable
{KEY MACRO X} Nested keyboard macro

Note: the "x" in the above codes represent a letter or number, and that {COMMAND} is representative of the commands in the macro commands list.



The one-line description provides a quick-reference to the purpose of the macro. You don't have to describe the macro if you don't want to when you first create the macro, and you always have the chance to edit the description later.

Key Sequence What it Does
1. [Ctrl]-[F10] Starts macro definition.
2. {name}
Enters the name of the existing macro.
3. 3 or D Chooses the edit Description option.

You may now edit the description as you like. The editing keys function as they normally do in WordPerfect. With the cursor positioned at the first character, typing anything erases the entire line. Press the [Enter] key when you are done.



This chapter discussed macro editing and how to use the keys on your keyboard to insert characters and macro codes, delete characters and codes, and format the macro for best readability.


 Top Contents

WordPerfect 5.1 Macros and Templates
Electronic Edition
Copyright 1990, 1997, Gordon McComb.  All Rights Reserved.
First published by Bantam Electronic Publishing, 1990.