VBATrain.com

    VBATrain Home    |    Samples TOC    |    Previous    |    Next    


Key Words: insert module -- name module

Insert and Name Modules

The code for this project will be writteOption Explicit: Requiring Variable Declaration in code modules. A code module is automatically inserted when you record a macro. Otherwise, you have to insert a module using menu commands or a toolbar button in the VB Editor.

We are going to use four code modules in the project. There is not technical reason for doing this since we are not using module-level variables. So, why not put all the code procedures in a single module? The reason is primarily organizational. We will organize our procedures using named code modules as containers. This will help you find project subs or functions more quickly.

Insert modules

There are three ways to insert a module from the VB Editor. They are shown below.
  1. Open the project workbook and go to the VB Editor.
  2. Execute menu command Insert > Module. Note that the new module is created with an Option Explicit statement in the Declarations (top) section of the module. This is due to setting the option Require Variable Declaration (see Option Explicit: Requiring Variable Declaration).
  3. insert module 1

    new module

  4. Now, insert a module by right-clicking in the Project pane and choosing Insert > Module.
  5. insert module right click

  6. Click on the drop-down arrow on the Insert UserForm button on the Standard toolbar (see figure below) and select Module.
  7. insert module toolbar

  8. Insert a fourth module using any of the methods shown above.

Name modules

  • Select one of the modules in the Project Explorer pane (it doesn't matter which one).
  • Name it "m1Main" (without the quotes) using the properties pane in the identical fashion in which you gave the worksheets object names, that is, by selecting the "(Name)" property of the module and typing "m1Main".
  • Name the other modules: "m2Legs", "m3Data", and "m9LastRow" (all without the quotes).
  • name modules

  • Save your work.

    VBATrain Home    |    Samples TOC    |    Previous    |    Next    

Click here for feedback and questions about this chapter.

Copyright © 2006-2008 J. Donald McClenagan, PhD, ALL RIGHTS RESERVED