Touring the Visual Basic Editor
The idea behind the Visual Basic Editor is simple: It's a separate program that's designed to do nothing else but help you create and edit VBA macros. (In professional programming circles, the Visual Basic Editor is called an
integrated development environment
the Visual Basic Editor for the first time, you don't see much. The left side of the editor has two
labeled Project and Properties. The latter you don't need to worry about right now. (I'll talk about it in Chapter 5, "Working with Objects.") The Project window (technically, it's called the Project Explorer) shows you the contents of the current VBA project. In simplest terms, a
is an Office file and all of its associated VBA items, including its macros and its user forms. (You learn about
forms in Chapter 13, "Creating Custom VBA Dialog Boxes.")
Opening an Existing Module
To do some work in the Visual Basic Editor, you usually start by opening a
, which is a VBA item that contains one or more macros. Here's how you do that:
In the Project window, open the Modules branch by clicking the plus sign (+) to its left.
of the module you want to open.
If you recorded a macro in Chapter 1, you should see a module named Module1. Go ahead and double-click that module to open it, as shown in Figure 2.2.
Figure 2.2. To write or edit a macro, first open the module you want to work with.
As you can see in Figure 2.2, the open module contains the macro code from my example in Chapter 1. I should also point out that each module window has two drop-down lists
the title bar:
This is the list on the left and it contains a list of the available objects for whatever project item you're working with. (I explain objects in detail in Chapter 5.) Modules don't contain objects, so this list contains only (General) for a module window.
This is the list on the right and it contains all the procedures and functions in the module. When you select an item from this list, the editor displays that item in the module window.
Creating a New Module
If you don't have an existing module, you can create one any time you like by selecting the Insert, Module command. The Visual Basic Editor
the module a generic name, such as Module1 or Module2, but you're free to rename the module. See "Renaming a Module," later in this chapter.