Chapter 2

LEARNING ADVANCED MACROS

There are a number of advanced macro features that are helpful in everyday applications of WordPerfect. These advanced features are part of WordPerfect, and are documented in the WordPerfect manual, but they are worth reiterating here. Many more advanced macro features are covered later in this book and a good number of these are not documented in the WordPerfect manual. These special features are tips and tricks that stretch the macro feature to provide new and unusual functions.

 

PAUSING MACROS FOR USER INPUT

Macros can be paused anywhere during playback and instructed to await direct keyboard entry. Pausing is helpful when you want to automate a process but still need to provide variable information. You can used paused macros, for example, to generated invoices. The macro creates the general form of the invoice, while pausing to allow you to enter data.

Another example is automating a standard form letter. One method of creating form letters is to use the merge print feature of WordPerfect. The merging process is time consuming if you mail out only a few letters. Another approach is to create a macro where standard (boilerplate) text is inserted for you. The computer stops at certain spots in the letter to allow you to enter specific information, such as the current date, the name of the addressee, the salutation, and so forth. Each pause ends when you press Enter.

Follow these steps to add a pause during a macro:

Key Sequence What it does
1. [Ctrl]-[F10] Begins a new macro definition.
2. {name} Names the macro. [Enter]
3. {description}
[Enter]
Describes the macro.
4. {macro steps} Defines the steps for the first portion of the macro.
5. [Ctrl]-[Page Up] Indicates that you want to add a pause.
6. [Return] Enters a pause.
7. {macro steps} Defines the steps for the remainder of the macro.
8. [Ctrl]-[F10] Completes macro definition.

Though the steps outlined above show one pause between two "macro steps" segments, you can insert as many pauses as you like during the macro. Simply repeat steps 5 and 6 for each new pause.

To use the paused macro, replay it as usual. When the pause is encountered, the macro halts and awaits text from the keyboard. Type the text and when finished, press [Enter]. The macro will continue and either end, or pause at the next stop. Always remember to press the [Enter] key when you are finished typing the text from the keyboard. This signals to WordPerfect that you are done with the entry and the macro continues.

IMPORTANT NOTE: While WordPerfect provides a "Macro Def" signal (in the lower-left corner of the screen) when you are defining a macro, it offers no such indicator when replaying a macro. You have no way of knowing if a macro is currently running. Adding pauses to a macro has the affect of momentarily freezing the macro and preventing it from continuing with the rest of the steps. But the macro is still active. If you're not sure whether a macro is still running, press the Macro Define ([Ctrl]-[F10]) key. If nothing happens, a macro is still in progress (when paused, you cannot define another macro). Future chapters will discuss other instances when a macro may appear to have stopped when in fact it's still running, and ways to provide your own "macro-in-progress" indicator.

 

Hands-On Pausing

Let's create a simple memo header using the pause feature. The memo will stop several times to allow you to enter the current date, the subject, and other pertinent information.

Key Sequence What it Does
1. [Ctrl]-[F10] Starts macro definition.
2. memo [Enter] Names the macro "memo."
3. Memo header [Enter] Describes the memo.
4. Date: Types Date:.
5. [Ctrl]-[Page Up] 1 [Enter] Pauses for Date: input.
6. [Enter] [Enter] One blank line.
7. Subject: Types Subject:.
8. [Ctrl]-[Page Up]
1 [Enter]
Pauses for Subject: input.
9. [Enter] [Enter] One blank line.
10. To: Types To:.
11. [Ctrl]-[Page Up]
1 [Enter]
Pauses for To: input.
12. [Enter] [Enter] One blank line.
13. From: Types From:.
14. [Ctrl]-[Page Up]
1 [Enter]
Pauses for From: input.
15. [Enter] [Enter] [Enter] Two blank lines.
16. [Ctrl]-[F10] Ends macro definition.

When you replay the macro, it will write the Date:, Subject:, To, and From:, allowing you time to manually enter in the specific information. Press the [Enter] key each time you finish with a line.

 

HIDING DISPLAY DURING MACRO EXECUTION

Normally, WordPerfect starts each macro with the display turned off. With the display off, commands and menus aren't shown during macro execution, and the macro works much faster. However, the screen may remain blank if the macro pauses at a menu. If your macro will pause at a menu, you must turn the display on before actually reaching the menu. A good place to turn the display back on is immediately before selecting a WordPerfect function, such as Help of Format.

Key Sequence What it Does
1. [Ctrl]-[F10] Begins a new macro definition.
2. {name}
[Enter]
Names the macro.
3. {description}
[Enter]
Describes the macro.
4. {macro steps} Defines the steps for the macro.
5. [Ctrl]-[Page Up] 2 Indicates that you want to control the display.
6. Y Turns the display on.
.... Rest of macro

The display option can be turned on and off at any point within the macro. Press [Ctrl]-[Page Up], then 2 to access the Display menu. Press N to turn the display off and Y to turn the display on.

IMPORTANT NOTE: The [Ctrl]-[Page Up] key is multi-purpose, and behaves differently depending on the activity of WordPerfect. You can select the Display and Pause options (plus two others that will be covered in later chapters) only when defining a macro from the keyboard. Chapter 3 outlines the many uses of the [Ctrl]-[Page up] key.

 

AUTOMATICALLY EXECUTING OTHER MACROS

Some operations, like changing between single and double space, require only one macro. More advanced operations, such as preparing a mailing list from a data document, filling out an invoice, or creating a table of contents, may require two or more macros, or else one large programmed macro. When using separate macros, you invoke each one in turn to complete the task. You can execute these macros manually -- starting each one with the [Alt]-[F10] key, or include commands within one macro to automatically run another.

How can using separate macros be beneficial over stuffing everything in one large macro? One reason is for simplicity. Separate macros are easier to create and edit, especially for the beginning "macroist." And, separate macros can be run either as a complete set, or independently. For example, you could create one macro that changes the margins, resets the tabs, and generates a header and footer. Or you could create several macros that each have a separate function. In the example,

Used this way, individual macros allow you a great deal of flexibility. You use only those macros that you need for a particular task. If you need to generate a header and footer, use just the header/footer macro. If you need to change the margins and tabs, use the margin and tabs macros. Of course, you need to replay each macro separately. That means more keystrokes for you as you recall all the macros in the set. And, separate macros tend to clutter up your disk. With so many macros to keep track of, you may forget which macro does what function.

Chaining Macros can start other macros. This is called chaining. With chaining, you can automatically step from one macro to the next. You start the first macro (the root) yourself. When the root macro finishes, it automatically calls up a second, or sub, macro. When that macro finishes, yet another one can be automatically started. You can continue these macro "links" to make a chain as long as you like.

Chaining relieves you of manually starting each macro in the set. But use chaining with caution. Macros refer to other macros in the chain by name, and if you delete a macro or alter its name, the chain will be broken. Keep a record of your macro chains to help you from inadvertently disturbing the links.

Follow these steps to make a macro chain. This example assumes you are creating a chained macro with two links; one called MACRO-A and the other called MACRO-B. For the sake of simplicity, we'll assume that MACRO-B already exists.

Key Sequence What it Does
1. [Ctrl]-[F10] Begins a new macro definition.
2. MACRO-A
[Enter]
Names the new macro MACRO-A.
3. Macro-A
[Enter]
Describes the macro as Macro-A.
4. {macro steps} . Defines the steps for MACRO-A
5. [Alt]-[F10] Starts sequence for MACRO-B chain.
6. MACRO-B
[Enter]
Indicates MACRO-B for chain.
7. [Ctrl]-[F10] Completes macro definition.

Note that MACRO-B is not actually replayed while you are creating MACRO-A. That prevents the keystrokes from MACRO-B from being included as part of MACRO-A. When you start MACRO-A, MACRO-B is automatically run. You can also start MACRO-B normally, without using MACRO-A.


Creating A Macro Linker

Another way to chain separate macros into a set is to use a separate macro "linker." The linker is a "bare-bones" macro that does nothing but call other macros. It does this by the use of nesting a procedure whereby WordPerfect starts one macro but before it has ended, branches off to another macro. When the second macro finishes, WordPerfect returns to the first macro. You can write the linker using WordPerfect's macro language, but if the macro is not too complex, you can create it directly from the keyboard.

First, build the branch macros that you want to use; that is, create the macros that you will be nesting to. Let's say that you are creating a macro set that includes three branches:

  1. Set margins to 1.5" on both sides.
  2. Remove all tabs but one at the 3" mark.
  3. Turn justification off and line numbering on.

Give each macro an Alt-letter name; nesting won't work otherwise (you can build nested macros without using Alt-letter macros, but it requires the use of the macro programming language). For our example, let's name these macros Alt-A, Alt-B, and Alt-C. Now create the linker macro, the one that will branch off to each of the three others in turn. Define the macro by pressing the [Alt]-A, [Alt]-B, and [Alt]-C keys in turn.


Hands-On Macro Nesting

So much for theory; now for practice. You can experiment with a simple macro linker by creating these four macros.

For Alt-A:

Key Sequence What it Does
1. [Ctrl]-[F10] Starts macro definition.
2. [Alt]-A Names the macro Alt-A
3. Macro A [Enter] Describes the macro.
4. This is Macro A
[Enter]
Text for macro.
5. [Ctrl]-[F10] Ends macro definition.

Repeat the same procedure for making the Alt-B and Alt-C macros, but change the names, description, and definition as required. When the the Alt-letter macros are finished, create the linker.

Key Sequence What it Does
1. [Ctrl]-[F10] Starts macro definition.
2. Linker
[Enter]
Names the macro ("Linker" in this example).
3. Linker macro to A,B,C
[Enter]
Describes the macro.
4. [Alt]-A Nests in macro Alt-A.
5. [Alt]-B Nests in macro Alt-B.
6. [Alt]-C Nests in macro Alt-C.
7. [Ctrl]-[F10] Ends macro definition.

When you run the linker macro, it branches off to each Alt-letter macro in turn. The screen should read:

This is Macro A
This is Macro B 
This is Macro C


Repeating Macros

You may repeat a macro as many times as you like using the [Esc] key. Before executing the macro, use the [Esc] key to indicate the number of times you want the macro repeated. For example, to repeat a macro named BOX five times, type the following:

Key Sequence What it Does
1. [Esc] Initiates repeat.
2. 5 Sets repeat to five times.
3. [Alt]-[F10] Invoke play back macro command.
4. BOX Indicates macro to run.
5. [Enter] Accepts the entry; macro is repeated five times.

Repeating Chains

Repeating chain macros use WordPerfect's search feature to automatically repeat a certain number of times. Repeating chain macros have an advantage over [Esc] key macros in that they will continue to work until the search results in a *not found* message. You don't have to manually calculate the number of times to repeat the macro.

Repeating chains use one macro that chains back to itself. Follow this procedure to create a repeating chain.

  1. Begin defining the macro.
  2. Enter the keystrokes and include a search of some type.
  3. Call the macro from within itself.
  4. End the macro

Though repeating chains can be useful, most of their applications can be duplicated using WordPerfect's Replace command. The exception is when you must make a change that can't be entered into the replace string. For example, say that you need to reformat a document that's been imported from another word processor. The file has five empty spaces at the beginning of each paragraph instead of tabs. What's worse is that the document lacks soft returns. It's a fairly long document and you don't want to hunt out each hard return in the middle of a paragraph and remove it. After exchanging the empty spaces for tabs, create this macro.

Key Sequence What it Does
1. [Ctrl]-[F10] Starts macro recordong
2. softconv [Enter] Names macro softconv.
3. Convert to soft returns
[Enter]
Defines macro.
4. [F2] Calls up search.
5. [Tab] Inserts [Tab] code in search string.
6. [F2] Starts search.
7. [Alt]-[F4] Turns block on.
8. [F2] [F2] Searches for next [Tab] code. [Tab]
9. [Left] [Left] [Left] Moves cursor back three spaces (past [Tab] and [HRt] codes).
10. [Alt]-[F2] n Calls us replace; no confirm.
11. [Enter] Inserts [HRt] code in search string.
12. [Alt]-[F2] Starts replace for selected block only.
13. [Alt]-[F10] softconv
[Enter]
Chains back to "softconv" macro.
14. [Ctrl]-[F10] Ends macro definition.

To use the macro, position the cursor at the beginning of the document and start the softconvmacro. The macro will repeat itself until it finds no more [Tab] codes, at which time the "*not found*" message is displayed and the macro ends.

The *not found* message indicates to WordPerfect that a type of error has occurred. In turn, WordPerfect halts macro execution, in case there is something seriously wrong. Repeating chain macros are a good example of how to take advantage of the error fail-safe feature built into WordPerfect. But you may have an occasion someday to construct a macro that ignores error conditions, or even does some specific action when an error occurs. Wordperfect 5.1 permits both, as explained in Chapter 4, "Learning the Macro Programming Language."


Conditional Chains

WordPerfect 4.2 provided a method of creating semi-intelligent macros by the use of "conditional chains." The technique takes advantage of the way the program's search feature works.  WordPerfect 5.1 does not allow you to construct conditional chains in the same manner, requiring instead that you write a conditional macro using programming statements, as described in Chapter 4. If you have version 4.2 conditional macros, you'll need to rewrite them in order to perform the same function in version 5.1.

 

IMPORTANT TOPICS

This chapter detailed the finer points of creating keyboard-recorded WordPerfect macros. You learned:

Key Sequence What it Does
1. [Ctrl]-[F10] Begins a new macro definition.
2. {name}
[Enter]
Names the macro.
3. {description}
[Enter]
Describes the macro.
4. {macro steps} Defines the steps for the first portion of the macro.
5. [Ctrl]-[Page Up] 1 Indicates that you want to a pause.
6. [Return] Enters a pause.
7. {macro steps} Defines the steps for the remainder of the macro.
8. [Ctrl]-[F10] Completes macro definition.

Repeat steps 5 and 6 for each pause. When replaying the macro, press [Enter] to finish the pause and continue execution.

Key Sequence What it Does
1. [Ctrl]-[F10] Begins a new macro definition.
2. {name}
[Enter]
Names the macro.
3. {description} [Enter] Describes the macro.
4. {macro steps} Defines the steps for the macro.
5. [Ctrl]-[Page Up] 2 Indicates that you want to control the display.
6. Y or N Turns the display on or turns the display off.
7. [Ctrl]-[F10] Completes macro definition.
Key Sequence What it Does
1. [Ctrl]-[F10] Starts macro definition.
2. {name}
[Enter]
Names the macro.
3. {description} [Enter] Describes the macro.
4. {steps} Defines first portion of macro.
5. [Alt]-# Nests in macro Alt-#.
6. {steps} Defines the rest of the macro.
7. [Ctrl]-[F10] Ends macro definition.

Repeat steps 5 and 6 for each new nested macro. The Alt-letter nested macros must already exist before you can redefine the main macro.

Key Sequence What it Does
1. [Esc] Initiates repeat.
2. # Sets repeat to five times.
3. [Alt]-[F10] Invoke play back macro command.
4. {macroname} Enters macro to use.
5. [Enter] Accepts the entry; macro is repeated # times.

---

 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.
http://www.gmccomb.com/.