MS-Excel / General Formatting

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 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 its associated VBA items, including its macros and its user forms.

Creating a New Module

You do most of your work in the Visual Basic Editor within one or more modules, which are windows designed to hold programming code. You may already have an existing module if you recorded some macros. Just in case, here are the steps to follow to create a new module:

  1. In the Project Explorer on the left side of the Visual Basic Editor window, click the project into which you want to insert the new module. Here are some notes to bear in mind:
    • In Word, if you want the new module's macros to be available all the time, click the Normal project (this adds the module to the Normal template).
    • In Excel, if you want the new module's macros to be available all the time, click the PERSONAL.XLSB project (this adds the module to the PERSONAL workbook).
      Remember that you won't see PERSONAL.XLSB until you store at least one recorded macro in the Personal Macro Workbook
    • In any program, if you want the new module's macros available only when a particular document is open, click that document or one of its objects.
  2. Choose Insert, Module. The Visual Basic Editor creates the new module and opens it.
  3. (Optional) In the Properties window, use the (Name) property to edit the module name, and then press Enter.

Opening an Existing Module

If you already have an existing module in the Project window, here are the steps to follow to open it:

  1. In the Project window, open a project by clicking the plus sign (+) to its left.
  2. In the project you just opened, open the Modules branch by clicking the plus sign (+) to its left.
  3. Double-click the name of the module you want to open. The Visual Basic Editor opens the module window and displays its VBA code.
[Previous] [Contents] [Next]