Objects, Collections, and Object Models: Technology Backgrounder

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Microsoft® Office XP applications expose their functionality to the Microsoft® Visual Basic® for Applications (VBA) language through a hierarchical system of objects and collections of objects called an object model. When you understand how to reference objects in an application's object model, you can use the objects and features available to build your solution.

An application fundamentally consists of two things: content and functionality. Content refers to the information within an application, that is, the documents, worksheets, tables, or slides and the information they contain. Content also refers to information about the attributes of individual elements in that application, such as the size of a window, the color of a graphic, or the font size of a word. Functionality refers to all the ways you can work with the content in the application, for example, opening, closing, adding, deleting, sending, copying, pasting, editing, or formatting the content in the application.

The content and functionality that make up an application are represented to the Visual Basic language as discrete units called objects. For the most part, the set of objects exposed by an application to VBA corresponds to all the objects that you can work with by using the application's user interface. You probably are familiar with many of these objects, such as Microsoft® Access databases, tables, queries, forms, and reports; Microsoft® Excel workbooks, worksheets, and cell ranges; Word documents, sections, paragraphs, sentences, and words; Microsoft® Outlook® messages, appointments, and contacts; Microsoft® PowerPoint® presentations and slides; and Microsoft® FrontPage®-based webs and web pages.

The objects exposed by an application are arranged relative to each other in hierarchical relationships. The top-level object in a Microsoft® Office XP application is the Application object, which represents the application itself. The Application object contains other objects that you have access to only when the Application object exists (that is, when an instance of the application itself is running). For example, the Excel Application object contains Workbook objects, and the Word Application object contains Document objects. Because the Document object depends on the existence of the Word Application object for its own existence, the Document object is said to be the child of the Application object; conversely, the Application object is said to be the parent of the Document object.

Many child objects have children of their own. For example, the Excel Workbook object contains, or is parent to, the Worksheets object. The Worksheets object is a special kind of object called a collection that represents a set of objects - in this case, all the worksheets in the workbook, which in turn are represented as individual Worksheet objects within that collection. A parent object can have multiple children; for instance, the Word Window object has as children the Document, Panes, Selection, and View objects. Additionally, identically named child objects might belong to more than one parent object; for instance, in Word, both the Application object and the Document object have a Windows collection as a child object. However, even though the child objects have the same name, typically, their functionality is determined by the parent object; for example, the Microsoft® Windows® collection for the Application object contains all the current document windows in the application, whereas the Windows collection for the Document object contains only the windows that display the specified document.

To view graphical representations of the object models for Office applications and shared components, see the topics Working with Microsoft Office Objects, Working with Microsoft Access Objects, Working with Microsoft Excel Objects, Working with Microsoft FrontPage Objects,, Working with Microsoft Outlook Objects, Working with Microsoft Word Objects, or Working with Microsoft PowerPoint Objects.

In addition to containing child objects, each object in the hierarchy contains content and functionality that apply both to the object itself and to all its child objects. The higher an object is in a hierarchy of nested objects (that is, the more child objects an object has), the wider the scope of its content and functionality. For example, in Excel, the Application object contains the size of the application window and the ability to quit the application; the Workbook object contains the file name and format of the workbook and the ability to save the workbook; the Worksheets collection contains Worksheet object names and the ability to add and delete worksheets.

You often do not get to the actual contents of a file, such as the values on an Excel worksheet or the text in a Word document, until you have navigated through several levels in the object hierarchy. This is because the scope of this specific content belongs to a particular functionality of the application. For example, the value in a cell on a worksheet applies only to that cell, not to all cells on the worksheet, so you cannot store the value directly in a Worksheet object.

To work with the content and functionality exposed by an object, you use properties and methods of that object. You use properties to determine or change some characteristic of an object, such as its color, dimensions, or state. For example, you can set the Visible property of an Excel Worksheet object to specify whether a worksheet is visible to the user. You use methods to perform a particular action on an object. For example, you use the PrintOut method of the Word Document object to print the document.

Some objects also respond to events. An event is an action that typically is performed by a user such as clicking a mouse, pressing a key, changing data, or opening a document or form but also can be performed by program code or by the system itself. You can write code, called an event procedure, which will run whenever an event occurs. For example, you can write code in a form's Open event to size or position the form whenever it is opened.

In summary, the representation of content and functionality in an application is divided among the objects in the application's object model. Together, the objects in the object model's hierarchy represent all the content and functionality in the application that is exposed to Visual Basic. Separately, the objects provide access to very specific areas of content and functionality. To determine or set a characteristic of an object, you read or set one of the object's properties. To perform an action on or with an object, you use one of the object's methods. Additionally, some objects provide events that are typically triggered by a user's action, so you can write code that will run in response to that action.

See Also

Office Objects and Object Models | Integrated Office Solution Development | Objects Exposed by an Object Model | Collections | Properties and Methods | Events | Using the Object Browser | Working with the Outlook Object Model | Office Application Automation