Code Modules

A code module can contain one or more procedures where a procedure is a subroutine or function.
Provides a way of organising your code
It is good practice to create several small subroutines or functions rather than one extremely long one.


Different Types

Workbook and Worksheet -
Userform Modules -
Class Module -
There are three different types of code module, standard, class and userform.
Code can be added to Events procedures which can be found within workbook, documents etc.


Inserting

To add a new module to a project, select the project name and select (Insert > Module).
You can also right click the project and choose (Insert > Module) from the shortcut menu.
You will also see the module appear in the project explorer window
A module name can have a maximum of 30 characters


Removing

If you need to remove a module select the module in the Project Explorer window and select (File > Remove ???)
where ??? Is the name of the module.
Alternatively you can also use the shortcut menu and select Remove ???/
You will be asked if you want to export the project before removing it.
More details about importing and exporting modules, please refer to the Visual Basic Editor > Components page.


If you want to delete all the macros from a workbook then it is much easier to do this using the Visual Basic Editor.
This way you can use the shortcut menu to quickly remove a code module from the project.
Select the code module you want to delete and press the right mouse button and select "Remove Module".
You will be asked if you want to export the module first. Select "No".
SS
It is not sufficient just to delete the VBA code from the code modules.
You must also remove any empty code modules from your workbook.
The Enable/Disable Macros dialog box will be displayed if there are any code modules in the workbook.


Remember

You can easily drag and drop modules between projects.
After making significant code changes it is always worth exporting your modules, deleting them from the project and then importing them again.
You cannot have two procedures or functions with the same name in the same module although you can in different modules.
When you record a macro a new standard module will be inserted automatically for you.


© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext