Microsoft Office Tutorials and References
In Depth Information
9.3 Object Model Hierarchies
For i = 0 To UserForms.Count - 1
Debug.Print UserForms(i).Name
Next i
(Note that this reports the number of loaded forms in the project.)
9.3 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)
Search JabSto ::

Custom Search