Ways to Avoid WordBasic Errors

Whenever you type a new instruction, you run the risk of misspelling a reserved word or leaving out a comma or a period and thereby creating an error. The techniques described in this section can help you reduce errors by reducing the number of instructions you type from scratch.

Use the Record Next Command Button

The Record Next Command button

If you need to include an unfamiliar statement in your macro and can't remember the names for the arguments you need, use the Record Next Command button on the Macro toolbar to record the instruction. The Record Next Command button turns on the macro recorder and records the next command you choose; Word then inserts the corresponding instruction in the macro-editing window. If a macro-editing window is not open, the Record Next Command button does nothing.

To use the Record Next Command button, position the insertion point in a macro-editing window at the place where you want to insert the instruction. If the command you want to record is not available in the macro-editing window, switch to a document window. Click the Record Next Command button, and then choose the command you want to record. If the command has a dialog box associated with it, set the options you want in the dialog box and then choose the OK or Close button (if you choose the Cancel button, the command is not recorded).

If you need to switch to a document window to record a command, be sure to switch before clicking the Record Next Command button. Otherwise, Word will record your switch to the document window rather than recording the command you choose. Of course, if the command is available in the macro-editing window, you do not have to switch to a document window.

Copy Syntax from Help

As useful as the Record Next Command button is, you can't use it to record WordBasic functions, nor can you record statements that do not correspond to Word commands. For these statements and functions, copying from Help is the solution.

If you know the statement or function name, you can type it in a macro-editing window and then, with the insertion point on the same line, press F1 (Windows) or HELP or COMMAND+/ (Macintosh) to display the Help topic for that statement or function. The Help topic for each statement and function includes its complete syntax. You can use the syntax simply to jog your memory or you can copy it directly into your macro. Many topics offer examples you can copy as well.

Store Instructions as AutoText Entries

Another way to minimize errors is to store frequently used instructions as AutoText entries. The capitalized letters in statement and function names lend themselves to a consistent and easy-to-remember naming system. You could store the EndOfLine statement, for example, in an AutoText entry named "eol." You may also want to store frequently used control structures such as If conditionals. As a further refinement, you could record a macro that not only inserts an If conditional, but also moves the insertion point to an appropriate place within the control structure so that you can begin typing immediately. If you create AutoText entries as you're working on a macro, it's not much of a chore, and in a short time you'll have a collection of entries that can help you put macros together very quickly.