Renaming the Module

When you record a macro or create a new procedure from scratch, Visual Basic creates a module folder to store your VBA code. The first folder is called Module1, the second one Module2, and so on. When you open up a new workbook and create VBA procedures, module folders in the new VBA project are again named Module1, Module2, and so on. Having modules with the same name can be very confusing not only to you but also to Visual Basic, as it tries to execute your macros or Visual Basic procedures in an environment where several projects are open.

To avoid the module confusion, assign unique names to Module1 in the FirstSteps (Chap01.xls) project and Personal (Personal.xls) project.

1. In the Project Explorer window, select the FirstSteps (Chap01.xls) project and choose Module1.

2. Double-click the (Name) property in the Properties window. This action selects the default module name Module1.

3. Type WorksheetFormatting for the name of Module1, and press Enter. Notice that the Project Explorer window now displays WorksheetFormatting as the name of the VBA module.

4. In the Project Explorer window, select Personal (Personal.xls).

5. Double-click the (Name) property in the Properties window.

6. Type Switches for the name of Module1, and press Enter.

Figure 2-2:

The Project Explorer window shows unique names that were assigned to VBA projects and modules using the Name property in the Properties window.

0 0

Responses

Post a comment