Microsoft Office 2000/Visual Basic Programmer's Guide   

Word Wizards

Word includes several wizards that are installed optionally; the Letter Wizard, the Memo Wizard, and the Résumé Wizard are a few examples. These files have the extension .wiz, but they are Word templates, so you can open them in Word and view their VBA projects. They're located in the C:\Program Files\Microsoft Office\Templates\1033 folder.

To create an application-specific wizard for Word, first create a Word template that contains any boilerplate text, plus the wizard forms and code. The wizard should include code that displays a form as soon as the user launches the wizard.

Next, determine how users will launch the wizard. If they will launch the wizard from a command bar control, you can add the control programmatically from code running in a Word add-in.

To design a wizard that is launched from a command bar control

  1. Add the AutoExec procedure to a standard module in the wizard's project, and include the code to create the control in that procedure.

  2. In the code that creates the control, set the control's OnAction property to the name of a procedure in the wizard project that displays the starting form for your wizard. For information about setting the OnAction property, search the Microsoft Word Visual Basic Reference Help index for "OnAction property."

  3. Add the AutoExit procedure, and include code to remove the control when the wizard is unloaded so that the user doesn't see the control unless the wizard is loaded.

  4. Load your wizard as an add-in in any of the ways described in "Loading a Word Add-in" earlier in this chapter.

If the user will launch the wizard by creating a new document, you don't need a command bar control or the AutoExec or AutoExit procedures.

To design a wizard that is launched by creating a new document

  1. In the wizard's VBA project, open the ThisDocument module.

  2. Create the Document_New event procedure by clicking Document in the Object box and New in the Procedure box.

  3. Within this event procedure, call the procedure that displays the wizard's starting form.

  4. Copy the wizard template to the C:\Windows\Application Data\Microsoft\Templates folder, or if user profiles are being used, to the C:\Windows\Profiles\UserName\Application Data\Microsoft\Templates folder, and change the file's extension to .wiz. Confirm this change when Windows prompts you to do so.

When users create a new document by clicking New on the File menu, they'll see your wizard displayed in the New dialog box. Clicking the wizard and then clicking OK creates a new document and runs the Document_New event procedure, which displays the wizard's starting form.