Workbook and Worksheet Object in Excel VBA
Last Updated :
30 Jan, 2023
Excel VBA is an object-oriented programming language, which means in excel every component is an object. The superset of all the objects of excel is the excel application itself. The Excel Application Object is the root of all the other objects in excel. It contains Workbook Object. The Workbook Object contains another object such as Worksheet Object which includes all the worksheets present in a particular workbook. The Worksheet Object contains Cells Object. To perform any task or operation in excel we need to follow this excel object hierarchy.

Â
Workbooks Object
In excel VBA, the workbooks object represents the collection of the workbook which are open in the excel application at the same time. This is the reason we write it as plural- Workbooks Object, which means it contains more than one workbook. In order to access a single workbook from the workbooks object, we can use the following VBA to access it from its name.

Â
How to Refer a Workbook in VBA?
To refer a workbook in excel VBA, we can use the following different methods:
By Name
We can easily refer to a workbook using its name. We need to define a procedure in VBA and declare our excel workbook name. Make sure that the user name is only if the workbook is not saved otherwise we need to define the name along with its extension.

Â
By Number
The excel application maintains an index order for all the workbooks we open. It gives numbers 1 to the first workbook, 2 to the second workbook, and so on. We can also use these numbers to refer to the workbook.
Note: It became really difficult to remember which workbook we have opened in which order. So, it is quite less used.

Â
By ActiveWorkbook Property
We can refer to a workbook using the ActiveWorkbook property. Using ActiveWorkbook we can refer to the workbook which is in an active state, which means the workbook is open in excel.

Â
Access Methods and Properties of a Workbook
Like any other object-oriented programming language, In VBA whenever we refer to an object it gives us access to all the methods and properties of that object. Similarly, when we access the Workbook Object, we get access to all its properties and methods.
Accessing Methods of Workbooks Object
In order to access the methods of the workbook object we will use the dot(.) operator. Once, we use our workbooks object as soon as we will use the dot(.) operator, it will display the list of methods associated with that particular object.

Â
Accessing Properties of Workbooks Object
Similar to methods, we can use the dot(.) operator to access the properties of the workbook object.

Â
As we can see, we have 3 different sheets currently open in our excel, if we run our procedure it will display the count as 3 in a message box.

Â
Worksheets Object
In excel VBA, the worksheets object represents the collection of the worksheets which are open in the excel workbook. This is the reason we write it as plural- Worksheets Object, which means it contains more than one worksheet.
How to Refer a Worksheet in VBA?
By Name
In excel, we can refer to a sheet using its name. By default, Excel creates sheets in natural number ordering. For example, Sheet1, Sheet2, etc. We can also give our own name to these sheets.

Â
By Number
We can also use sheet numbers to refer to a sheet in excel. The two operations to refer to a sheet, Sheets() and Worksheets() work in different ways while accessing the sheets by number.
Operation
|
Working
|
Sheets(n)
|
This is used to refer to the nth sheet starting from the first sheet |
Worksheets(n)
|
This is used to refer to the nth sheet itself. |

Â
By ActiveSheet Property
In excel VBA, we can also refer to a sheet using the ActiveSheet property.

Â
As above, we can see we have the GFGCourse sheet active. When we run our procedure, it will pop up a message box with the active sheet name is.

Â
Access Method and Properties of a Worksheet
Similar to the Workbook object, Worksheet Object also comes up with different methods and properties. In excel VBA, we can access methods and properties of excel worksheet objects using the dot(.) operator.

Â
Similar Reads
Protecting Excel Worksheets and Workbooks
Have you ever come across an Excel sheet that's locked, stopping you from making changes or updates? Whether itâs to prevent accidental changes or to keep sensitive information safe, sometimes you need to remove that protection to get back to editing. If you're wondering how to break Excel sheet pro
12 min read
Creating the Workbook and Worksheet using openpyxl in Python
Openpyxl is a Python library designed to read and write Excel (xlsx/xlsm/xltx/xltm) files. It's a great tool for automating Excel operations in Python, making it easier to create, modify, and extract information from Excel files. Openpyxl is a Python library that lets us work with Excel files direct
6 min read
How to Protect a Workbook in MS Excel?
Every day in school, offices, business sectors or any other field lots of information are there that are required to store for the future use. For anyone, it is very difficult to remember that information for a long time. Earlier data and information are stored in a form of a register, file, or pape
4 min read
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
Workbooks in Microsoft Excel
Spreadsheet programs have become essential for many organizations for analyzing and storing data and if we talk about the most recognized spreadsheet program, then it will be MS Excel. Now, if you have worked with Microsoft Excel, then you have heard about the terms workbooks and worksheets. In the
5 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
Worksheets in Excel
If you're new to MS Excel, you've likely heard the term "worksheet." But have you ever wondered what an Excel worksheet actually is? So, in a spreadsheet program, a worksheet is a collection of cells (it is a basic data unit in the worksheet) where you can store and manipulate data. By default, ever
5 min read
Basic Object Model in Excel VBA
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 t
3 min read
How to Create Charts in Excel Using Worksheet Data and VBA?
Excel is an important software provided by Microsoft Corporation. This software belongs to one of the major software suites Office 365. In this software suite, there are other software are present like Word, PowerPoint, etc. They are called Office 365, as this software are mostly used for office pur
6 min read
How to Protect Sheet in Excel
How to Protect a Sheet in Excel- Quick Steps Right Click on the Worksheet Tab Select Protect Sheet >>Enter Password Select the Actions you want to allow the UsersClick OkWhen working with sensitive or shared data in Excel, ensuring the security of specific sheets is essential. Excel sheet prot
8 min read