Microsoft Office Tutorials and References
In Depth Information
9.1.2 Methods
Because a Chart object can be obtained from a Workbook object, we refer to Chart as a child
object of Workbook and Workbook as a parent of Chart. We will have more to say about this
parent-child relationship a bit later.
9.1.2 Methods
A method of an object is an action that can be performed on (or on behalf of ) the object. For
instance, a Worksheet object has a Protect method that causes the worksheet to be protected.
In programming terms, the properties and methods of an object are just built-in functions or
subroutines. It is important to emphasize that the distinction between property and method is one
of intent and is often made somewhat arbitrarily. (In fact, the Item member is sometimes classified
as a property and sometimes as a method, depending upon the object in question; it appears that
even Microsoft has trouble making up its collective mind from time to time.)
The properties and methods of an object are collectively referred to as the object's members . This
should not be confused with an object's children.
9.2 Collection Objects
In programming with the Excel object model (or indeed any object model), it is common to have a
great many objects "alive" at the same time. For instance, each cell within the current selection is
an object (a Range object), as is each row and column in each open worksheet. Hence, at any
given time, there are thousands of objects in existence. To manage these objects, the designers of
an object model generally include a special type of object called a collection object .
As the name implies, collection objects represent collections of objects—generally objects of a
single type. For instance, the Excel object model has a collection object called Rows that
represents the set of all rows in the worksheet in question (as Range objects). It is customary to
say that the Rows collection object contains the rows in the sheet, so we will use this terminology
as well. There is one Rows collection for each open worksheet.
Collection objects are generally just called collections , but it is very important to remember that a
collection is just a special type of object. As we will see, the properties and methods of a
Collection object are specifically designed to manage the collection.
We can generally spot a collection object by the fact that its name is the plural of the name of the
objects contained within the collection. For instance, the Worksheets collection contains
Worksheet objects. However, in some cases, this naming convention is not followed. For instance,
the Rows collection contains Range objects. In the Excel object model, there are no Cell, Row, or
Column objects. These are all represented by Range objects. We will devote an entire chapter
Chapter 19 ) to the important Range object. (
Collections are extremely common in the Office object models. In fact, almost one-half of all of
the objects in the Excel object model are collections! Table 9-1 s hows some of the more
commonly used collections in the Excel object model.
Table 9-1. Some Excel Collection Objects
Search JabSto ::

Custom Search