Object Browser in VBA

Today we will learn an important topic which is using the Object Browser in VBA. It is very important to learn and is helpful for efficient VBA programming. We will learn to search for properties, methods, and events of an Object using Object Browser.

So let us start learning.

Objects and Classes

VBA is not a fully Object Oriented language but involves the concept of Classes and Objects. Objects are the actual entities we work with and have their existence in Excel. For example, different Worksheets, Workbooks, Ranges, or Charts are the Objects.

A Class is like a blueprint of the Object. It holds the instructions or VBA code to use an Object as an Object is an instance of a Class. Every Object has its own methods and properties defined in the Class. The Class does not have an actual existence like an Object.

What is Object Browser?

An Object Browser can be opened in Visual Basic Editor and has information about all the Libraries and their Classes. It contains the list of all the methods, properties, and events belonging to each class.

Follow these steps to open the Object Browser in Visual Basic Editor.

  • Open Excel and press Alt and F11 keys to open the Visual Basic Editor (VBE).
  • Go to the View tab on the ribbon. Click on Object Browser to open it.
How to Open Object Browser in VBA

Alternatively, press the F2 key or open the Object Browser from the Tool Box.

open object browser from toolbox in vba
infographics object browser in VBA

The Interface of Object Browser

When you open the Object Browser in VBA, it will have the following panes.

parts of object browser in VBA in Excel

The following points explain the importance of different panes and buttons in the Object Browser in VBA.

  • <All Libraries> – This is a drop-down list showing the selected libraries for your Excel. Libraries contain predefined classes.
  • Search Box – This search box can search any Class, Method, Property, or Event.
  • Class Pane – contains a list of all the classes of the selected library. By default, it displays the list of all <All Libraries> libraries.
  • Members Pane – This shows all the members of a Class selected in the Class Pane. The members of a Class can be properties, methods, or events.
  • Details Pane – This pane shows detailed information about the class member selected in the Members Pane.

Searching an Object using Object Browser

We can use the search box to search an Object using the Object Browser. Let us suppose we wish to search for Application then the following search results appear as follows.

search for an object using Object Browser using VBA

The Members Pane consists of a list of all the Members of the Application Class.

Class Members in Object Browser

The list of class members consists of different properties, methods and events. So let us study each of them

Properties of Object in VBA

A Property refers to the characteristic of the Object. It can have its value. Property is capable of returning an Object, Collection, or Enumeration. Let us understand with the help of examples.

Properties Returning Object

In the Members Pane, when we search for Application Class, we will see a property named as ActiveCell. The ActiveCell property returns a Range Object that is referring to the Active Cell in the worksheet.

property returning an object in vba

Property Returning Collection

The Collection refers to the grouping of similar objects using Indexing. We have predefined collections like Worksheets Collection that contains all the Worksheet Objects.

You will find the Worksheets Property of Application Class that returns the Sheets Collection.

property returning collection in vba

Property Returning Enumeration

The Calculations property of the Application class return enumeration XlCalculations. Enumeration or Enum refers to the value assigned to constants.

property returning enumeration in VBA

When you click on XlCalculation, it opens the members of this enumeration.

members of enumeration using object browser

Methods of Objects in VBA

The Objects have different methods associated with them in their class definition. Method or Function refers to the execution of code for that object for completing a procedure. For example, we can use the InputBox function of the Application Class to take input from the user.

methods of objects in object browser

Events of Objects in VBA

Event Handlers contain the specific code to execute when the user triggers a specific event associated with that object. For instance, we have different events in the Application class which are SheetActivate, SheetBeforeDelete, SheetBeforeDoubleClick, and many more events that have their syntax.

This brings us to end.

Thank you for reading. ❤

Leave a Comment