Before you start developing in VBA, you should familiarize yourself with the various components of the VBA development environment (see Figure 33.1). Figure 33.1. The VBA development environment contains several panes and toolbars.Some of the VBA windows and menus are dockable, meaning that they can be moved and attached to the top, bottom, left, or right of the screen. Others operate as multiple document interface windows, with multiple windows displayed in one master window. Using the Project ExplorerThe Project Explorer contains all the modules, forms, and class modules in your project. Items are grouped by type. You can display the code associated with any of these items simply by double-clicking it. The top level of the Project tree is the Microsoft Outlook Objects branch. There is always one object in this branch: the ThisOutlookSession object. This is where you place code that works at the application level. The next branch of the Project tree is Forms. This branch holds any VBA forms you've created for your application. Next is the Modules branch, which contains general code that isn't specifically related to an application-level event. If you have code that needs to be available to multiple areas of the application, place it in a module. You can also program procedures and functions in a module to run in response to a click of a toolbar button. You can also create multiple modules in your project. For instance, if you have a set of functions or procedures that operate only on calendar items, you might want to create a calendar module to hold all of this code. That way, when you need to access one of these procedures, you know exactly where it's stored. When you create a new module, name the module with the prefix bas. This prefix has historically been used to name standard modules. The last branch of the tree contains class modules. These modules can contain a variety of different functions. Unlike standard modules, however, class modules require that an instance of the class be created before any of the functions within can be used. Class modules are typically named with the prefix CLS. To add a new file to your project, right-click anywhere in the Project window and select Insert from the context menu. From here you can insert a userform, module, or class module. You can then rename the new file using the Properties window, which is usually located immediately below the Project window. If you can't see the Properties window, select View, Properties Window to display it. Using the Properties WindowThe Properties window enables you to view and change any editable properties of any selected object. You can rename forms, modules, and class modules, or configure any controls on a VBA userform. Figure 33.2 shows the Properties window for a combo box in a VBA userform. Figure 33.2. A combo box has many properties you can change.Debugging ToolsThere are three main tools you can use within VBA to debug your code:
VBA ToolbarsOutlook's VBA development environment contains a number of toolbar buttons designed to help with the most common tasks in VBA. For more information about the specific toolbar buttons you might find helpful, see Table 33.1.
|