You are currently viewing VBA Code Editor | Create, Edit and Save VBA Codes
Visual tutorial explaining the components and interface of the VBA Editor (VBE) in Excel and Access

VBA Code Editor | Create, Edit and Save VBA Codes

VBA Code Editor, abbreviated as VBE (Visual Basic Editor), is a tool used for creating, editing, and maintaining VBA procedures and modules in Microsoft Office applications such as Excel and Access.

Quick tour of the Visual Basic Editor and running your first VBA macro in Excel.

Prerequisite for this section:
How to open VBA Editor?

Table of Contents

Introduction

The VBA Code Editor or VBE is a software environment where you can write, run, compile, and debug program code. In this section of Iran VBA’s free tutorials, we will examine different parts of this editor.

The default VBA Code Editor page can be divided into 6 main sections as shown in the figure, each of which we will explain in the following.

Screenshot of six main sections of the VBA Editor (Menu Bar, Toolbar, Project Explorer, Properties Window, Code Window, Immediate Window) highlighted and numbered in red
This image displays the six key areas of the VBA Editor, highlighted and numbered in red for easy identification.

Section 1: Menu Bar

Screenshot of VBA Editor menu bar highlighted with pointer and blurred background
This image highlights the main menu bar of the VBA Editor with a pointer for easy identification.

Like most Windows programs, VBE is also equipped with a menu bar. The menu bar contains various dropdown menus, each containing commands related to the menu title.
You may have noticed that some commands in the menus have shortcut keys displayed next to them. These shortcuts play an important role in increasing the speed of accessing frequently used commands.
In the figure below, you can see the shortcut keys for commands in the Debug menu.

Screenshot of VBA Editor Debug menu with keyboard shortcuts highlighted in red
This image shows the VBA Editor Debug menu with its keyboard shortcuts highlighted in red for easier learning.

Section 2: Toolbar

Screenshot of the VBA Editor toolbar highlighted with a pointer and blurred background
This image shows the VBA Editor toolbar highlighted with a pointer while the rest of the interface is blurred for emphasis.

The toolbar, like the menu bar, is a familiar part of most computer programs. As shown in the figure, the toolbar consists of a series of tools and commands displayed to the user as icons.
The toolbar shown in the figure above is the standard VBA Code Editor toolbar, which is enabled by default in VBE. However, VBE also has three other toolbars:

  • Debug toolbar
  • Edit toolbar
  • UserForm toolbar

In addition to the above toolbars, VBE also provides users with the ability to customize the toolbar.

To change the toolbar or customize it, you can use the View menu and then select the Toolbars submenu.

Screenshot of the VBA Editor showing the View menu with the Toolbars submenu highlighted in red
This image shows the VBA Editor’s View menu with the Toolbars submenu highlighted in red, used to show or hide toolbars.

Section 3: Project Explorer Window

Screenshot of the VBA Editor with the Project Explorer window highlighted by a pointer
This image shows the Project Explorer in the VBA Editor, highlighted by a pointer, which displays the structure of VBA projects and modules.

A Project in VBA is defined as a collection of modules. The Project Explorer window in VBE displays all modules available in a project.
VBE displays the project modules in this window as a tree diagram, categorized by module type.

If this window is inactive for you, you can activate it from the View menu by clicking on Project Explorer or pressing the Ctrl+R key combination. The different parts of the Project window are shown in the image below.

Screenshot of the Project Explorer window in the VBA Editor (VBE) of Excel and Access with labeled sections
Overview of the Project Explorer window in the VBA Editor, showing its components for managing projects and modules

As shown in the image, class objects are objects designed by Microsoft and added by the user to the project.
For example, in the figure above, Form_Form1 is an Access form object saved by the user as Form1. Class objects in an Access file can be of form or report type.
The difference between standard modules and classes lies in the programming method used in these two modules. Programming in standard modules is procedural programming, while in class modules it is object-oriented programming.
It is noteworthy that class objects are essentially class modules that have been programmed and designed by Microsoft.

Section 4: Properties Window

The Properties window displays the properties of the class object that is in edit mode in the Project window. In this window, you can view the properties of a class or module.
For example, if you open a form in Design View in Access, the properties of the opened form will be displayed in this window.
If this window is not displayed in your code editor, you can display it again by pressing the F4 key or from the View menu.

Screenshot of the VBA Editor (VBE) showing a selected object in the Project Explorer with its properties displayed in the Properties window
Viewing and editing the selected object’s properties through the Project Explorer and Properties window in the VBA Editor

Section 5: Programming Window/Code Window/Module Window

Screenshot of the VBA Editor showing the Code Window area highlighted in red
The Code Window in the VBA Editor is where you write and edit Visual Basic for Applications (VBA) code and macros.

In this window, you can view or edit the codes stored in each module. This window functions similarly to a text editor.
To view the codes of any module, you can double-click on the desired module icon in the Project window.

Section 6: Immediate Window

Screenshot of the VBA Editor showing the Immediate Window area highlighted in red
The Immediate Window in the VBA Editor is used to test commands, run code snippets, and view outputs during debugging.

The main purpose of the Immediate Window is debugging and testing VBA codes. This window is the VBA programmer’s assistant in debugging codes.
While running program codes, you can view the contents of the Immediate Window by pressing the Ctrl+G key combination.

Read More

Leave a Reply