Modules

The Project Explorer lists a node for each module within the project. Modules contain general procedures, either functions or subroutines. Excel creates a new module for a project each time you add a new macro to the corresponding workbook. You can add other modules within the Visual Basic Editor, as outlined later in this chapter. Not all modules contain macros that are visible within Excel. You can create hidden procedures that are called by other functions and subroutines.

PROPERTIES WINDOW

The Properties window displays the properties for the selected object. If you select a module in the Project Explorer, the only properties you see in the Properties window is the module name. If you select a specific sheet, however, you can view and modify properties for a sheet such as whether page breaks display.

To change the properties for an object, you simply click the property and make the desired changes. Some property fields, such as Name, require you to type a value. Other fields have drop-down lists where you can select the appropriate value. If you find that you cannot change its property, it is probably read-only and you cannot modify it.

VBE AND INTELLISENSE TECHNOLOGY

To make adding VBA code easier, the Visual Basic Editor uses Microsoft's IntelliSense technology, which helps you find the properties and methods for the objects you use in your macro scripts. As you type the name of an object, a list of available properties and objects display from which to select. You can select from this list by clicking the selection with the mouse. Any property or method that you select appears in your code in the Code window.

ACTIVATE THE VISUAL BASIC EDITOR

You can only run the Visual Basic Editor from a Microsoft Office application. The Visual Basic Editor provides the ability to create and modify Excel macros using Visual Basic for Applications, or VBA. You can activate the Visual Basic Editor by editing a macro that you recorded with the Macro Recorder, or you can open the editor directly from the Tools menu via the Visual Basic Editor option. Whether you create a macro using the Macro Recorder or in the Visual Basic Editor, you write all source code using VBA. Of course, with the Macro Recorder, Excel takes the key strokes that you record and converts them all to VBA.

When you open the Visual Basic Editor, the Project Explorer, if displayed, indicates your location within the project. If you open an existing macro from the Macro dialog box within Excel, the Project Explorer highlights the corresponding module in the tree and the VBA code for the macro appears in the Code window. When you select the Visual Basic Editor directly, however, the Project Explorer highlights the name of the current project, which is the name of the workbook open in Excel. You can select a specific module in a project by double-clicking the module node in the Project Explorer. To learn more about nodes and the structure of the Project Explorer, see the section, "An Introduction to the Visual Basic Editor."

Keep in mind that if the Personal Macro Workbook, Personal.xls, contains macros, the project for the Personal.xls project always opens when you access the Visual Basic Editor. Although the Personal Macro Workbook is hidden within Excel, in the Visual Basic Editor you can view and modify all macros in the Personal Macro Workbook.

See Chapter 3 for more information on using Visual Basic for Applications (VBA).

ACTIVATE THE VISUAL BASIC EDITOR

ACTIVATE THE VISUAL BASIC EDITOR

0 0

Post a comment