Introduction to Visual Basic Editor Window

How to enable the Developer Ribbon Tab?

In order to work with VBA, users need to make a small change in Excel to display a new tab (Developer) at the top of the screen. Microsoft Excel does not display the Developer ribbon tab by default. So, getting Excel to display the developer tab, follow these steps.

Method 1

  • File -> Options -> Excel Options -> Customize Ribbon -> Check Developer -> Click OK
Introduction to Visual Basic Editor Window

OR

Method 2

  • Click anywhere on the Ribbon and choose to Customize the Ribbon
  • Look at the right side of the Customize the Ribbon dialog box
  • Checkmark next to Developer
  • Click OK

Developer Ribbon Tab

The Developer tab contains the most powerful tools in Excel that allow you to create and access macros, to develop and customize Excel. Developer Ribbon Tab has further three sections which are explained below:

  1. Code: This section is used to open VBA Editor, view, record, and manage your macro security option.
  2. Add-ins: This option allows the user to manage the Add-ins, Excel Add-ins and COM Add-ins
  3. Controls: This section enables the user to view the VBA code, set properties, activate the form, and insert ActiveX controls.
  4. XML: This option manages the importing/ exporting Data and XML extension packs options.
Introduction to Visual Basic Editor Window 1

What is Visual Basic Editor?

Visual Basic Editor (VBE) is an environment which is used to write the VBA codes. You can’t run VBE separately, and Excel must be open for VBE to run. It is used to create, modify, debug, and maintain the VBA (Visual Basic for Applications) procedures, codes, and modules in Excel. The Visual Basic Editor (VBE) is contained in the Microsoft Excel workbook.

Introduction to Visual Basic Editor Window 2

How to activate VBE ?

There are two procedures to activate the Visual Basic Editor window in Excel.

Option 1

Press ALT + F11

Option 2

Choose Developer -> Code Visual Basic

Components of VBE

The components of the VBE are as follows:

Menu Bar: VBE has a Menu Bar which has menus like File, Edit, View, Insert, … and other Toolbars, like Standard, Debug, Edit & UserForm Toolbars where you can add Commands like Save, Print, Delete, Undo, Redo,

Code Window: This is the area in VBE in which you write the codes and records the macros. On the top right is the Procedure list with which you can quickly move to another procedure in the active module. At the bottom of the code window, you can adjust between the Procedure view, which displays a single procedure in the active module, and the Full Module view, which is the default view and displays all procedures in the active module.

Project Explorer: It displays the list of all existing projects. It represents the modules and sheets in a hierarchical view wherein you can fail to hide or expand to view the objects, user forms, and modules included in a project. The project contains Object Folders, Forms folder, Modules Folder, and Class Folder. The object folder is the default folder and consists of a sheet object and This workbook object within it.

Properties Window: This window in VBE presents a list of properties for the selected object or variables, which can be modified here. To display the Properties Window, click on View in the Menu Bar -> select Properties Window or press the F4 button. It is used to edit the User-Form properties, controls properties, unlike TextBox, ComboBox, CommandButton, etc.

Procedure Box: Procedure box contains a list of the existing individual macros or procedures within the active module under the 'Declarations' heading.

Object Box: Object box displays 'General', which is the default object. It is used to select an object to work unlike worksheet, workbook, user form, checkbox etc.,

The Immediate Window: The Immediate Window facilitates debugging the VBA code and allows the user to check the output of an individual line of code. Hence, it provides an ease to rectify if there is an error in the code. You can type the code and then press enter to execute, which enables immediate execution of the method or procedure. To show the Immediate Window, click on View in the VBE Menu Bar and select Immediate Window, or press the shortcut keys, CTRL+G.

Introduction to Visual Basic Editor Window 3

The Locals Window: This window displays the name, value and type for all declared variables in the current procedure automatically and updates the variables' values while the code is executed and hence, is used in VBE as a debugging tool. To view the Locals Window, click on View in the VBE Menu Bar and then select Locals Window.

The Watch Window:  The Watch Window helps you to view and monitor the current value of a variable or expression, whose name, amount, type, and context are to be displayed in the Window. You need to explicitly add a variable or expression to the Watch window which you want to monitor, unlike in the Locals Window, where all the expressions and variables are displayed automatically in the current procedure. To add the variable or expression to the Watch window, select it and right-click and then click Add Watch, or select it and click Add Watch or Quick Watch on the Debug menu, or press the shortcut keys Shift+F9. To display the Watch Window, click on View in the VBE Menu Bar and then select Watch Window.

The VBE Environment

Visual basic environment or VBE is an Integrated Development Environment (IDE) developed by Microsoft. It uses a Graphical user interface with a basic programming language and is the first software to provide a graphical programming environment for developing a user interface module or applications.

In VBE, a considerable volume of code gets swapped by the controls, where the user must drag and drop to add any control in the interface. This environment does not have any object-oriented programming language concept.

Various attributes and event handling are coupled with the controls and default values are assigned to the controls when it is created, and it is possible to change the default values. This environment primarily allows to create a windows application, additionally create executable (exe) files, ActiveX controls, and DLL files.