Add A New Module

You can create new code modules directly within the Visual Basic Editor. VBA uses modules to store variable declarations and all procedures, including functions and subroutines. Whenever you create a new macro using the Macro Recorder, Excel generates a new module within the corresponding project to house the new macro. Excel places the macro code in a subroutine with the same name as the macro. See Chapter 3 for more information on procedures, including functions and subroutines.

You do not need to rely on Excel to create the new modules for your macros because you can create them directly within the Visual Basic Editor. After creating a module, you can create a subroutine within the module and add the desired code so that the Macro dialog box lists your macro within Excel. Of course, in order for Excel to make the macro visible, you must create a public subroutine. See Chapter 3 for more information about working with subroutines.

As you add new modules to a project, Excel gives them the name Module#. The Visual Basic Editor assigns the number to the macro, sequentially increasing the number by one each time you add a macro. For example, the Visual Basic Editor names the first module in the project Module1, the second Module2, and so on.

The Project Explorer lists all of the modules within a specific project. When you add a new module, Excel selects that module on the Project Explorer and creates a blank Code window.

You do not have to create a new module for each procedure that you add to a workbook. You can add multiple procedures to the same module, if desired.

ADD A NEW MODULE

ADD A NEW MODULE

-D Click the project where you want to add a new module.

Click Insert O Module.

Excel creates a blank Code window.

0 0

Post a comment