| To add existing macro code to a module, edit a recorded macro, or build your own macros from scratch, you use the Visual Basic Editor. You saw earlier that one way to open the Visual Basic Editor is to display the Macros dialog box, select a macro, and then click Edit. However, if you just want access to the editor, the more normal route is to select Tools, Macro, Visual Basic Editor, or click the Visual Basic Editor button in the Visual Basic toolbar (you can also press Alt+F11). | The Visual Basic Editor is a so-called integrated development environment, which means it has tools and objects that enable programmers to write and edit VBA code. The Visual Basic Editor is divided into three areas (as shown in Figure 11.4): Project Explorer This area shows the open VBA projects as well as a hierarchical view of the contents of each project. These contents include the open application objects (worksheets, documents, slides, and so on), any modules that have been created either by recording a macro or by creating one from scratch (explained later), and any user forms that you've built. Properties window This area shows the various properties available for whatever object is highlighted in the Project Explorer. The Properties window is divided into two columns. The left column shows you the names of all the properties associated with the object, and the right side shows you the current value of each property. To change the value of a property, click the appropriate box in the right column and then either type in the new value or select it from a drop-down list (the method you use depends on the property). Work area This is where the module windows you work with are displayed. Figure 11.4. The Visual Basic Editor is a complete programming environment. Creating a Module To create a module, follow these steps: 1. | In the Visual Basic Editor, use the Project pane to click the workbook project in which you want to insert the module. For example, if you want to use the Personal Macro Workbook in Excel, click the PERSONAL.XLS project. | 2. | Choose Insert, Module, or drop down the Insert list (pointed out in Figure 11.4) and select Module. The Visual Basic Editor adds a Modules branch (if one didn't already exist) to the workbook's project and opens the Module window. | Opening a Module Later, when you've created modules in various workbooks, you'll need to know how to open the module that contains the code you want. You have two choices: Choose Tools, Macro, Macros (or press Alt+F8) to display the Macros dialog box, use the Macro Name list to click the macro you want to work with, and then choose Edit. The program launches the Visual Basic Editor and opens the module containing the macro. In the Visual Basic Editor, use the Project window to open the branch of the workbook that contains the module, open that project's Modules branch, and then double-click the name of the module you want to open. I should also point out that each module window has two drop-down lists beneath the title bar (refer to Figure 11.4): Object list This control contains a list of the available objects. Modules don't have objects, so this list contains only (General) for a module window. Macro list This is a list of all the command macros and function macros in the module. Until you add a macro, this list shows only (Declarations). |