Object Model Hierarchies

The fact that one object's properties and methods can return another object, thus creating the concept of child objects, is of paramount importance, for it adds a very useful structure to the object model.

It seems by looking at the literature that there is not total agreement on when one object is considered a child of another object. For our purposes, if object A has a property or method that returns object B, then we will consider object B to be a child of object A and object A to be a parent of object B. For example, the Range object has a Font property, which returns a Font object. Hence, Font is a child of Range and Range is a parent of Font. The Font object is also a child of the ChartArea object, which represents the chart area within an Excel chart. (We will discuss this object in Chapter 21.) In fact, an object may have many parents and many children.

It is important not to take the parent-child analogy too literally. For instance, the object hierarchy is full of circular parent-child relationships. As an example, Range is a child of Worksheet and Worksheet is a child of Range. Indeed, in most object models, most objects have a property that returns the top object of the model. In the Excel object model, almost every object has an Application property that returns the Application object, which is the top object in the Excel object model. This provides a quick way to return to the top of the object hierarchy. Hence, almost every object in the object model is a parent of the top object!

The object hierarchy of an object model is often pictured in a tree-like structure. A small portion of the Excel object model is shown in Figure 9-1.

Figure 9-1. A small portion of the Excel object model (the tag <vX> means that the object is new in version X of Excel)

■ 7 o Application

o

■¡EVSAIS ?

+

7U

Add Ins

?o

AyipCoiTect

7 o

AuloRecoverivl. >

?o

C-- IForiTiaKvl 0>

+

7 o

Chart

±

?U

Ch carts

7 o

D efeu itWebQptia ns<vS>

?U

D iahgi

7 &

EirjiCheckingOpiioniiulOi

?U

NnmEE

*

7U

QDBCErrors

+

?U

QLEDBErroii8<v9>

7U

P.angs

-i-

7U

Ret^mfFilei

7 ^

RTDcvlOi

7LI

Sheeis

+

7U

Srr artTagReco ;r i?ers<v10>

7 o

Speech <vlG>

7 o

Spellircg0piDns<v1Q*

7U

UiedObjec(s<vi >

?U

Walches<v1 0>

4

? o

Window

+

7U

Windows

■+

? c

Workbook

+

?U

Workbooks

7U

WorkshoelFundion

V

?U

Worksheets

+1 0

Responses

Post a comment