Excel VBA Object Model And Object References: The Essential Guide

Tutorial about the Excel VBA Object Model and Object References

If you've read any of the other macro or VBA tutorials in Power Spreadsheets, you've probably noticed that some terms keep popping up over and over.

One of the concepts that keep coming up, and will continue to come up in future tutorials, is that of objects. The main reason for this is simple:

VBA is (loosely) based on Object Oriented Programming. At a basic level, this (roughly) means that the VBA paradigm mostly relies on working with (or manipulates) objects.

As a consequence of the above, if you want to really master Excel macros and Visual Basic for Applications, you must have a good understanding of the following 3 topics:

My 2 main purposes when writing this VBA tutorial are to:

  1. Explain the main characteristics of Excel's VBA object model.
  2. Illustrate how you construct VBA object references when working with Visual Basic for Applications. This allows you to identify the Excel VBA object you want to work with and manipulate.

More precisely, in this macro tutorial I explain the following topics:

Table of Contents

I'll say from the start that the topics of Excel's VBA object model and building VBA object references are not particularly simple. However…

Your knowledge and understanding of Excel's VBA object model and object references will improve as you continue to study, and work with, Visual Basic for Applications. Therefore, don't worry if, after reading this VBA tutorial things are not absolutely clear. This guide should provide you with a solid base and, with some work I'm sure you'll master this topic and know all you need about Excel VBA objects.

Let's begin by answering the first question that you probably have regarding the introduction I've made above by understanding…

Why Excel's VBA Object Model Is Important

Visual Basic for Applications is included in most products that are part of Microsoft Office. In addition to Excel, the list of applications that have VBA includes PowerPoint, Word and Access.

This underscores one of the great advantaged of learning VBA:

Once you know Visual Basic for Applications, you can immediately start writing macros for the other products that use VBA. In fact, you'll be able to create macros that work across all of those different applications.

One of the main topics you need to master in order to reach those levels of expertise is objects. At a basic level, VBA manipulates objects.

Each individual Application that works with VBA (for example, Excel, Word, PowerPoint, Outlook) has its own unique object model. Having a good understanding of the principles behind objects and object models helps you work with VBA in these different Applications.

OK. So Excel's VBA object model is clearly important. The next question you may have is…

What Is Excel's VBA Object Model

At a basic level, the Excel VBA Object Model is a hierarchy of the objects you can use when working with Excel VBA.

Among other advantages, this hierarchy makes VBA objects easier to reference. Therefore, let's take a closer look at…

Excel's VBA Object Hierarchy

Excel object model - hierarchy image

An object hierarchy looks as follows:

When you're working with a particular software application, the first object to consider is the application itself (the Application object). Generally, the application is at the top of the hierarchy.

In the case of Excel, the Application object is Excel itself.

Since Visual Basic for Applications can communicate with other applications and programs beyond Excel, this isn't strictly speaking the top level of the hierarchy. However, you'll usually see most people referring to the Application object itself as being the top of Excel's VBA object hierarchy. That's the convention I use in this macro tutorial.

The Application object contains other VBA objects. Some of the VBA objects contained by the Excel Application object are the following:

Each of these VBA objects, in turn, is capable of containing other objects. For example, some of the VBA objects that can be contained within a Workbook object are the following:

Again, these VBA objects can contain other objects. Continuing with the example above, a Worksheet object can contain the following VBA objects: