Microsoft Office Tutorials and References
In Depth Information
Chapter 9. Object Models
Chapter 9. Object Models
In this chapter, we present a general overview of object models and the syntax used to manipulate
them in code.
As we have discussed, VBA is the programming language that underlies several important
Windows applications, including Microsoft Excel, Word, Access, PowerPoint, Visual Basic, and,
in Office 2000, Outlook. Any application that uses VBA in this way is called a host application .
We also discussed the fact that each host application enhances VBA by providing an object model
(perhaps more than one) to deal with the objects that are particular to that application.
Microsoft provides over a dozen different object models for its Office application suite and related
products. These include object models for Excel, Word, Access, DAO (Data Access Objects),
Outlook, PowerPoint, Binder, Graph, Forms, VBA, VB, ASP (Active Server Pages), and more. Of
course, our interest in this topic is with the Excel object model, and we will devote most of the rest
of the topic to describing the major portions of this model. (We will also discuss a portion of the
Office object model in the chapter on customizing Excel menus and toolbars.)
9.1 Objects, Properties, and Methods
In the parlance of VBA programming, an object is something that is identified by its properties
and its methods. For example, workbooks, worksheets, charts, and fonts are all examples of
objects in the Excel object model. Actually, the Excel object model contains 192 different objects,
including several hidden and obsolete ones.
9.1.1 Properties
The term property is used in the present context in pretty much the same way that it is used in
everyday English; it is a trait or attribute or characteristic of an object. For instance, a Worksheet
object has 55 properties, among which are Cells, Name, ProtectionMode, and UsedRange. A
property's value can be any valid data type, such as Integer, Single, String, or even another object
type.
When the value of a property has type Integer, for instance, we will refer to the property as an
integer property . Integer properties are quite common, and so Microsoft has defined a large
number of built-in enums (152, to be exact, with 1266 individual constants) to give symbolic
names to these property values. For instance, the Calculation property of the Application object
can take on any of the values in the enum defined by:
Enum XlCalculation
xlCalculationManual = -4135
xlCalculationAutomatic = -4105
xlCalculationSemiautomatic = 2
End Enum
If a property's value is an object, it is referred to as an object property . For instance, a Workbook
object has an ActiveChart property that returns a Chart object. Of course, the Chart object has its
own set of properties and methods.
 
 
Search JabSto ::




Custom Search