Understanding the Structure of a Module
Modules are workbook sheets that contain code. Each module can contain a declarations section, followed by procedures. The declarations section at the top of the module can contain:
- Option statements. If your module contains any Option statements, which set various module-level options, these statements must appear before any procedures. For more information, see "option" in Help.
- User-defined type definitions. If your module contains any user-defined types, their definitions must appear before any procedures. For more information about user-defined types, see Chapter 2, "Variables, Constants, and Data Types."
- Declarations. Any variable or constant declarations that aren't contained within a procedure must be placed before any procedures in the module. For more information about declaring variables and constants, see Chapter 2, "Variables, Constants, and Data Types."
Except for Option statements, user-defined type definitions, and declarations, all code in Visual Basic must be contained within procedures; Visual Basic modules cannot contain free-floating (uncontained) commands.