The Visual Basic Editor
Before a Visual Basic for Applications (VBA) program can be written, you need to know where to put it. Within Microsoft Excel, VBA code is written in the Visual Basic Editor (VBE). This is accessible on the main Excel Ribbon Menu, or by hitting ALT+F11 on the keyboard.
The VBE may be a screen you’re unfamiliar with. The user interface is relatively simple and is split into 5 key sections:
- Menu Bar: Similar to the menus you’re used to in most windows applications, it allows access to all the commands available within the Visual Basic Editor.
- Toolbar: Allows quick access to ta number of regularly used commands.
- Project Explorer: All VBA programs form part of a larger project which encompasses the parent Excel workbook, worksheets, charts etc. together with code modules which contain the actual VBA programs. The Project Explorer is a visual overview of the structure of the project, allowing quick access to the objects and modules within it.
- Properties Window: Some objects and modules have properties or attributes. Each property has an associated value, which can be manipulated using the Properties Window.
- Main Workspace: The principle work area. All files and modules opened in the Visual Basic Editor appear in the Main Workspace.
All VBA programs are placed in code modules, which are interactive windows in which your code can be typed, copied and pasted. Each project can have as many modules as required. Consequently, more complex projects are broken down into many modules; whereas small projects can often be stored in a single module.
There are several types of code modules including standard, userform and class modules. In general, and especially at an introductory level, all VBA code will be place in a standard code module, often just referred to as ‘Modules’. We’ll get into the other types, and the functionality they offer, in a later lesson.
Adding a New Standard Code Module
Adding a new module is easy, just right click anywhere within the Project Explorer (see Figure 1 above), then select Insert > Module. This will create, and automatically open in the Main Workspace.
Congratulations! You just created your ‘Module1’ you first step into the depths of VBA. You should have seen a new blank window pop up, this is where you’ll soon be writing your own VBA code.
If you would like more information on the Visual Basic Editor, please visit MSDN: