Moving Project Items Among Templates and Documents

VBA macros are stored in projects. A project is a collection of modules, and in Word, each document or template contains a single project. Within each project, macros are stored in modules. A module is a collection of VBA code, such as procedures, functions, and other declarations. A project can contain any number of modules. Each macro is stored as a procedure, or collection of VBA statements, in a module. Each module can contain as many individual macros as you want. When you record a macro, Word stores the VBA code in a module named NewMacros.

NOTE

Modules can be added, renamed, and otherwise manipulated as required to obtain the desired functionality.


If you have a module containing some useful macros in a given template, you might want to reuse that module in another template. You can use Word's Organizer to copy macros from one project to another:

  1. Choose Tools, Macro, Macros, or press Alt+F8, to display the Macros dialog box.

  2. Click Organizer. The Organizer dialog box appears, as shown in Figure 32.8. This dialog box lets you display the modules in two templates or documents and copy modules from one list to another.

    Figure 32.8. Use the Organizer to copy modules from one template or document to another.

    graphics/32fig08.gif

  3. Under either list, you can display a different template by clicking the Close File button, and then clicking Open File and selecting a different template or document.

  4. To copy a module from one list to another, select the module that you want to copy and click Copy. The macro is copied to the destination list. If a module with the same name is already in the destination project, Word won't let you copy the module. If you still want to copy the module, you must rename it before copying it (see the next step).

  5. To rename a module, select the module and click Rename. Type the new name for the module and click OK.

  6. To delete a module from a project, select the module and click Delete. Word asks for confirmation that you really want to delete the module.

    CAUTION

    After you delete a module and save the template that contained it, there is no way to recover the deleted module.

  7. When you are finished using the Organizer, click Close.

The Organizer copies, renames, and deletes only entire modules, each of which might contain many individual macros.



    Part I: Word Basics: Get Productive Fast
    Part II: Building Slicker Documents Faster
    Part III: The Visual Word: Making Documents Look Great
    Part IV: Industrial-Strength Document Production Techniques
    Part VI: The Corporate Word