Basic Object Model in Excel VBA
Last Updated :
27 Jan, 2023
VBA stands for visual basic for application. Excel VBA is an object-based programming language, it is used while recording a macro i.e., it uses the idea of Encapsulation and stores the state (data) and operation (functions) inside the object. Excel objects are arranged in a hierarchy that governs the excel object. Every element in excel is represented by an object in VBA. Below are the basic excel elements,

Excel Objects
In the above picture, we can have the following different objects:
- Workbook Object - We have one excel workbook open so, we have 1 workbook object. For example, if we have 3 different excel workbooks, then we have 3 workbook objects.
- Worksheet Object - A workbook object has a worksheet object. Here, we have 3 different worksheet objects.i.e., Sheet1, Sheet2, and Sheet3.
- Range Object - Inside a worksheet object we can have a range object. Here, we have RangeObject(B5:D9).
- ActiveCell Object - Inside a range object or a worksheet object we can have a cell object.
- Cell Object - Inside a cell object we can have Font, Size, Color, Value, Border, and so on.., various objects.
The excel objects are arranged in a hierarchy and they act as the container for the other excel objects. In the hierarchy we have Excel Application Object at the top, the excel application object contains WorkbookObject, WindowObjcet, etc., the workbook object contains WorksheetObject, ChartsObject, etc., the worksheet object contains RangeObject, ShapeObject, ChartObject, etc., the range object contains CellObject, the cell object contains Font Object, Interior Object, Border Object, etc.
Example: In this example, we will define a macro in excel, we will enter the code inside that macro, and execute the code to understand the working of various excel objects.
Step 1: In this step, we will write our VBA code in the visual basic editor. For this go to Developer and then select Visual Basic Editor.
The Visual Basic Code Editor is now open, we can begin writing our VBA script.
Step 2: In this step, we will write our VBA scripts. Double-clicking ThisWorkbook under Microsoft Excel Objects in the left pan will do this. The editor will then be opened, and the following code will be entered into it.

'function name
Sub ObjectHierarcy()
 Application.Workbooks(1).Worksheets("Sheet1").Range("A1").Value = "GeeksForGeeks"
 Â
 'Here, we are using Application Object to access Workbook Object
 'and then using workbook object we are accessing WorkSheet Object
 'and adding Value "GeeksForGeeks" in cell A1
 Â
End Sub
We will write this code in the VBS script editor and execute it. This will print the output string in the cells(A1) defined in the code.
Once we run it by pressing the Run button, the result will look like this.
Similar Reads
VBA Objects in Excel Objects are created from the class. If we take some real-life examples then let's say a Dog is a class where it has its properties and methods like breed, age, and color whereas we can say Dog1 or Dog2 are objects having different breeds, ages, and colors. We can simply say the object is a grouping
4 min read
Application Objects in Excel VBA The Excel VBA Application object is one of the most commonly utilized objects when using VBA to automate any task. It uses several Excel programs and runs various operations on Excel Workbooks. To work with the Excel Application Object, it has many Properties and Methods. Below is a brief descriptio
2 min read
Data Models in Excel Power View The Data Model gives us the ability to work with multiple tables and integrate them with each other using a specified relationship to build a relational database inside Microsoft Excel. It helps to work with larger datasets and provides us with a huge set of interactive features for creating, modify
5 min read
How to Delete a Module in Excel VBA? Have you ever seen a text file in a notepad or a source code file in visual studio code? These all are just basic files where you can write some code or information. Similarly, we have modules in excel, each module has its code window, where you can write some code and allow it to automate your repe
3 min read
Sub Procedure in Excel VBA A Sub Procedure is an action that is written in VBA code. It starts with a Sub statement and ends with an End Sub statement. It is used to manipulate the data in an Excel sheet which includes a table present in an Excel sheet or a pivot table present in the Excel sheet. The name of the procedure sho
3 min read
Assigning Excel Macro to Objects In Excel, a recorded macro can be assigned to different objects like a shape, graphic, or control note. Instead of running the macro from the required tool in ribbon, we can create these objects to run them easily. They get very handy when multiple macros are there. Individual objects can be created
3 min read
VBA Arithmetic Operators in Excel Arithmetic Operators are the operators which perform mathematical operation or which perform any operation between two numbers like addition(+), subtraction(-), multiplication(*), division( / ), exponentiation(^), modulus(Mod), Bit-Shift operations. In this article, we will learn about the excel VBA
3 min read
VBA Logical Operators in Excel Logical operators are used for performing logical and arithmetic operations on a set of values or variables. VBA allows you to use the Logical operators AND, OR, NOT, and XOR to compare values. The operators are considered "Boolean" which means they return True or False as a result. In Excel VBA, lo
6 min read
How to Run Code from a Module in Excel VBA VBA Macro is for developers. In Excel, the macro is a piece of code written in VBA and VBA is Microsoft's programming language, it stands for Visual Basic for Applications. The module is a file with a .bcf extension that stores the code written in the Visual Basic for Applications editor. Let's lear
4 min read
VBA Arrays in Excel Arrays are used to store data of similar data types. Suppose there are 300 students rather than declaring 300 variables for students, we can declare one array where we can store 300 elements. In this article, we will learn about excel VBA arrays. Declaration of Array Declaring an array is similar to
5 min read