Vba modules in Excel

Whenever a new macro is created in excel, it is stored in a separate entity called Module.

A module can be viewed in the VBA editor window at the left pane.

A new module is created, every time, a new VBA editor window is opened.

To understand the above point, consider you are creating a new macro as explained in earlier chapter.

Now, there will be a VBA editor window with a sub created. Now close this window and create a new macro.

Now the VBA editor opens again, but this new sub will be placed in another newly created module.

But, If the same sub was created manually below the first sub, this will be placed in the same module itself.

A collection of all modules consitiute a "Project".

There are three types of modules which are as discussed below:

General or Standard Modules

These modules corresponds to macros created from the Excel View tab.

They are placed under "Modules Folder" as Shown below:

excel vba modules

WorkBook Module

This module is related to the Entire workbook and there is always only one module of this type for any workbook.

excel vba modules

"ThisWorkbook" is the Workbook module.

All the events corresponding to the workbook can be coded here.

Worksheet Module

This module is related to the worksheet.And there as many modules as number of worksheets, each corresponding to a single worsheet. Worksheet modules only work on the sheet they are in.

excel vba modules

The above screenshot shows the worksheet modules.

 

You can find similar Excel Questions and Answer hereunder

1) How to convert a number or string into a data with the cdate function

2) Various important math functions in VBA (trigonometry, algebra, exponential, �)

3) How to format variable with VBA with the very useful format function. Define the number of decimal, the way a date is formated

4) What are the date and time function in Excel VBA

5) How to use logical operators in VBA

6) What is a function in VBA. How to create a function and how to call a function

7) How to create a subroutine in Excel VBA. Subroutines explained

8) How can worksheet functions be accessed in VBA?

9) How to modify strings in VBA, what are the functions you can manipulate strings with

10) What is variable scope in VBA, how do variable can be reach from other function or routines in VBA

 

Here the previous and next chapter