The Excel Visual Basic Editor

The easiest way to access the Visual Basic Editor in Excel is to press the key combination ALT-F11 (ie. press the ALT key, and while this is pressed down, press F11). You will be presented with the Visual Basic Editor, similar to the image below (note that your normal Excel window will remain open behind this window).

Excel Visual Basic Editor

There are a number of windows that can be viewed in the Excel VBA Editor. These are controlled via the View menu at the top of the VBA Editor window. The individual windows are described below.

The Project Window

Empty VBA Editor Project Window

The Project Window opens up on the left of the VBA Editor (as shown in the above image). This window provides you with an index of all Visual Basic files, linked to all open Excel workbooks. These consist of:

A file (or a worksheet object), linked to each worksheet of your Excel workbook


Additional files (called Modules), which contain user-defined code and are not linked to any specific worksheet

If you want to write a macro that is to be linked to a specific worksheet, then this code should be entered into the relevant worksheet object. If your code is more general, you may want to create a new module to hold this.

The Code Windows

In the Visual Basic Editor image above, the code window for the Module 1 is displayed.

The Code Window contains the VBA code for each individual worksheet object or module. Once a worksheet object or module is opened up, you can type your VBA code directly into the code window and the VBA editor assists you with typing in valid VBA code by highlighting lines that do not adhere to the VBA code rules, as you type.

The code window for an existing worksheet object or module is opened up by double-clicking on the worksheet or module name in the Project Window. Alternatively, you can create a new module as follows:

  1. If you have more than one Excel workbook open, in the 'Project Window', select the workbook you want to add a module to
  2. Right click in the 'Project Window' and select Insert->Module

The Properties Window

Empty VBA Editor Properties Window

The Properties Window lists the properties of the object that is selected in the Project Windowat design time (ie. not during run time). These properties vary, depending on the type of object that is selected (a worksheet, workbook, module, etc).

The Immediate Window

Excel Visual Basic Immediate Window

View the Immediate Window by selecting View→Immediate Window from the Visual Basic Editor, or by pressing CTRL-G.

This window assists with the debugging of code by acting as an output window for debug statements or by allowing you to evaluate expressions or execute individual lines of code.

For example, the expression, ?j followed by the return key will print out the current value of the variable j.

A useful article on the Immediate Window is provided at

The Locals Window

Excel Visual Basic Locals Window

View the Locals Window by selecting View→Locals Window from the Visual Basic Editor. This window displays all local variables that are declared in the current procedure. It is split into columns which show the name, value and type of each variable and updates these values automatically, as the programme is executed. The Locals window is therefore useful for debugging VBA code.

The Watch Window

Excel Visual Basic Watch Window

The Watch Window is also useful when debugging VBA code, as it shows the value, type and context of any watch expressions that have been defined by the user.

The Watch Window can opened by selecting View→Watch Window from the Visual Basic Editor, or the window appears automatically when a 'watch' expression is defined. to define a 'watch' expression:

  1. Highlight an expression within the VBA code
  2. From the Debug menu at the top of the VBA editor, select the option Quick Watch...
  3. Click on Add

The menus at the top of the Excel Visual Basic Editor contain numerous options and commands for designing, executing and debugging VBA code. Further information on the VBA editor can be found at (opens in a new window).