|< Day Day Up >|| |
You use the Project Explorer to manage your projects and modules within the Visual Basic Editor. It lets you create new modules, delete modules, and copy modules from one project to another. About the only thing you can’t do in the Project Explorer is create a new project (for that, you need to create a new workbook), but you can use the Project Explorer to manage the contents of the project.
All macros and procedures are stored within a VBA module. You can have more than one module within a project, and that might even be necessary depending upon the complexity of your project.
To create a new module, click Insert and then click Module, Class Module, or UserForm, depending on the type of module you want to create. Figure 4-9 shows a recently created blank module in a project. Once you’ve created the module, you can begin adding procedures or designing the user form. Another option is to import a module from a text file. By clicking File, Import File, you can select a text file that includes the code to be used in other modules or user forms. The Visual Basic Editor creates a new module, so unless the code you import is a complete procedure it won’t run until you add the Sub…End Sub notation.
Figure 4-9: Creating a new module gives you a place to put your code.
If a module is no longer needed within a project, you can delete it. Select the module you want to remove from within the Project Explorer, and then click File, Remove Module Name. Module Name will change to reflect the name of the module that is currently selected. Before deleting the module, the Visual Basic Editor will ask if you want to export the module to a text file, as shown in Figure 4-10. This gives you an opportunity to backup a module before it is completely removed.
Figure 4-10: It’s probably a good idea to take the opportunity presented by the Export File dialog box to save deleted code in a text file, just in case.
You can export a module at any time by clicking File, Export.
The Project Explorer provides an easy method for copying modules from one project to another. To do so, open the source project and the destination project and then, from within the Project Explorer window, click the module you want to copy from the source project and drag it to the destination module. Once the mouse pointer is within the destination project, it will change appearance from a circle with a line through it to an arrow with an outline box and plus sign beneath it, as shown in Figure 4-11.
Figure 4-11: The mouse pointer changes to indicate a valid drop-off point when copying modules.
If you copy a module into a project that already has a module of the same name, the Visual Basic Editor will rename the module by adding a number behind the name, starting with 1 and incrementing each time a module of the same name is copied. Also, if there are no modules of the type you’re moving, the Visual Basic Editor will create a module and the appropriate folder to hold it.
|< Day Day Up >|| |