Users and Developers Are Separated

In Microsoft Excel 5/95, macro code was placed in VBA module sheets and dialogs were created on dialog sheets. Both of these sheet types existed alongside worksheets and chart sheets in the Microsoft Excel workbook. While most developers would hide module and dialog sheets from users, if you wanted to you could view all of them together in the workbook.

In Microsoft Excel 97, rather than adding module and dialog sheets to the same window used for worksheets and charts, all programming is done from the Visual Basic Editor (VBE). This allows a much richer programming environment that is separate from the worksheet and chart window. You access the VBE from the Microsoft Excel menu by choosing Tools/Macro/Visual Basic Editor or by using the ALT+F11 keys to toggle between the two windows.

In addition to the standard code modules found in previous versions of Microsoft Excel, UserForms, Worksheets, and the Workbook object all contain modules where you can place code that applies to them. Microsoft Excel 97 also includes the ability to create Class Modules. In this chapter we'll refer to the three modules types as Standard Modules, created when you choose Insert/Module in the VBE; Object Modules, which hold the "code behind objects"; and Class Modules. This is a design enhancement that allows you to modularize your code.

Standard Modules are equivalent to module sheets in Microsoft Excel 5/95. Class Modules are a new type of module that allow you to create custom objects. Object Modules are a specific type of class module associated with certain VBA and Microsoft Excel 97 objects.

Good coding practice suggests that you keep all the code that pertains to a given object in one place, and Microsoft Excel 97 VBA allows you to do this. For example: dialog boxes and Wizards are built from Microsoft Excel 97 UserForms. These UserForms contain an Object Module that handles the code associated with objects placed on the UserForm (and the UserForm itself). This may include dialog initialization, error handling, and control code. Your Standard Modules can then call your dialog code with a single entry point, and the dialog will respond based on the code in its Object Module. If you copy an object, its code in the Object Module is copied as well, so you could copy a User Form and add it to another workbook and its associated code would be included automatically.

It's important to recognize that the Object Module behind a UserForm may also call code in the Standard Modules of your project. Microsoft Excel doesn't force you to place all the associated code in the Object Module, but in most cases this is the best practice.