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.
SS


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.


Option Private Module

When used in host applications that allow references across multiple projects, Option Private Module prevents a module's contents from being referenced outside its project.

Option Private Module 

If used, the Option Private statement must appear at module level, before any procedures.
When a module contains Option Private Module, the public parts, for example, variables, objects, and user defined types declared at module level, are still available within the project containing the module, but they are not available to other applications or projects.
Option Private is only useful for host applications that support simultaneous loading of multiple projects and permit references between the loaded projects.


Important

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.


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