Microsoft Excel Objects, Application Object, Workbook...

Microsoft Excel Objects

The object model of MS Excel and other Microsoft Office applications is organized as follows. At the zero level of the hierarchy, there is a central object, in which other objects that constitute the first level of the hierarchy are embedded. Objects of the next level can be built into each of the objects of the first and subsequent levels. Embedding is implemented using object properties. Properties can be terminal, non-objects, and properties that return objects when they are called.

There are a lot of objects in this hierarchy. Considering that each object, in turn, has a large number of properties, methods and events, it is rather difficult to study them. Therefore, we will consider only the main objects. At first, it's enough to use the Application, Workbook '), Worksheet, Range. There are many in this hierarchy and collections: Workbooks is a collection of workbooks, Worksheets - a collection of worksheets, Sheets - a collection of all sheets (worksheets and charts), Charts - a collection of diagrams.

A full description of the properties, methods and events of each object can be found in the help system. To do this, open the Help window in the Visual Basic Editor, in the search bar, type Application Object Members (for the Application object) and go to the hyperlink found. For other objects, use the appropriate class name instead of Application.

Application object

At the top of the object model is the Application object. It represents the Excel application itself. Through this object, all other objects are accessed. However, the properties and methods of this object are usually used without specifying the word Application. For example, instead of Application. ActiveCell.Value can be written just ActiveCell.Value. The main properties of the object are given in Table. 12.21.

Table 12.21

Basic object properties Application



Active Workbook,

Active Window,




Active objects (workbook, window, sheet, chart, cell)


Represents a container object that contains Excel functions. 'For example, for example, we can refer to the Excel function FACTUR, which calculates the factorial: WorksheetFunction.Fact (5) in the VBA program. The names of functions in the United States version of Excel do not match the properties of the Worksheet Function. To find out the name of the desired property (the function name in the English version), write down the macro that uses this function on the worksheet and look at the function name in the macro text


A collection of all workbooks


The selected object in the active window. The type of the object depends on the current selection. Nothing is returned if there is no selected object in the active window

The Quit method of the Application object terminates Excel. For example, the following code saves all open Excel workbooks and exits the application:

For Each wb In Application.Workbooks




Workbook Object and Workbooks Collection

Each workbook is represented by the Workbook object, and their collection is the Workbooks object. Methods of the Workbooks collection are given in Table. 12.22.

Table 12.22

Collection methods Workbooks




Adds a new workbook to the collection. Returns the created workbook as a result


Opens an existing workbook: Workbooks.Open d: Book1.xlsx


Closes all books in the collection

These methods have parameters. More details about the parameters can be found in the help system. The easiest way to do this is to call the context-sensitive help: position the cursor in the program text on the name of the property or method of interest, and press the F1 key.

The main properties and methods of the Workbook object are shown in Table. 12.23 and 12.24.

Table 12.23

Basic properties of the Workbook



Sheets, Charts, Worksheets

Collections of all worksheet sheets, charts, worksheets


The full name of the workbook, specified as a string, including the path to the file that stores the workbook. Has the status of read-only


A property that is True if no changes have been made since the last time the work was saved

Table 12.24

Basic object methods Workbook



Save, SaveAs

Allow to save the workbook without closing it and removing it from the Workbooks collection. The first time you save, you must use the SaveAs method to specify the name of the file in which the book is saved


Closes books) 'and removes it from the collection. For example, you can close the workbook Bookl without saving:

Workbooks ("Book1.xls"). Close SaveChanges: = False


Activates the workbook

Ошибка в функции вывода объектов.