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 or IDE .)

When you open the Visual Basic Editor for the first time, you don't see much. The left side of the editor has two windows 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 project is an Office file and all of its associated VBA items, including its macros and its user forms. (You learn about user 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 module , which is a VBA item that contains one or more macros. Here's how you do that:

  1. In the Project window, open the Modules branch by clicking the plus sign (+) to its left.

  2. Double-click the name 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.

graphics/02fig02.jpg

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 beneath the title bar:

Object list 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.

Procedure list 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 assigns 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.



Absolute Beginner's Guide to VBA
Absolute Beginners Guide to VBA
ISBN: 0789730766
EAN: 2147483647
Year: 2003
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net