Microsoft Office Tutorials and References
In Depth Information
About Objects and Collections
About Objects and Collections
If you’ve worked through the first part of this chapter, you have an overview of VBA, and you
know the basics of working with VBA modules in the VBE. You’ve also seen some VBA code and
were exposed to concepts like objects and properties. This section gives you additional details
about objects and collections of objects.
When you work with VBA, you must understand the concept of objects and Excel’s object model.
It helps to think of objects in terms of a hierarchy. At the top of this model is the Application
object — in this case, Excel itself. But if you’re programming in VBA with Microsoft Word, the
Application object is Word.
The object hierarchy
The Application object (that is, Excel) contains other objects. Here are a few examples of
objects contained in the Application object:
h Workbooks (a collection of all Workbook objects)
h Windows (a collection of all Window objects)
h AddIns (a collection of all AddIn objects)
Some objects can contain other objects. For example, the Workbooks collection consists of all
open Workbook objects, and a Workbook object contains other objects, a few of which are as
follows:
h Worksheets (a collection of Worksheet objects)
h Charts (a collection of Chart objects)
h Names (a collection of Name objects)
Each of these objects, in turn, can contain other objects. The Worksheets collection consists of
all Worksheet objects in a Workbook . A Worksheet object contains many other objects,
which include the following:
h ChartObjects (a collection of ChartObject objects)
h Range
h PageSetup
h PivotTables (a collection of PivotTable objects)
If this seems confusing, trust me, it will make sense, and you’ll eventually realize that this object
hierarchy setup is quite logical and well structured. By the way, the complete Excel object model
is covered in the Help system.
 
Search JabSto ::




Custom Search