Microsoft® 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. You can open them in Word and view their VBA projects.
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
- Add the AutoExec procedure to a standard module in the wizard's project, and include the code to create the control in that procedure.
- 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.
- Add the AutoExit procedure, and include code to remove the control when the wizard is unloaded, so the user does not see the control unless the wizard is loaded.
- Load your wizard as an add-in.
If the user will launch the wizard by creating a new document, you are not required to have a command bar control, nor the AutoExec nor AutoExit procedures.
To design a wizard that is launched by creating a new document
- In the wizard's VBA project, open the ThisDocument module.
- Create the Document_New event procedure by clicking Document in the Object box and New in the Procedure box.
- Within this event procedure, call the procedure that displays the wizard's starting form.
- 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 will see your wizard displayed in the New dialog box. Clicking the wizard and then clicking OK creates a new document and runs the Document_NewEvent procedure, which displays the wizard's starting form.