O'Reilly logo

Programming Excel with VBA and .NET by Steve Saunders, Jeff Webb

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Common Members

Most objects in Excel have several members in common as listed in Table 4-5.

Table 4-5. Common Excel object members

Member

Description

Use to

Application

Returns the Excel Application object

This isn’t really useful from within Excel since the Application object is readily available anyway. It’s somewhat useful when programming Excel from other applications, however.

Creator

Returns a numeric code identifying the application that created the object

Again, this isn’t really useful from within Excel. You can pretty much ignore this property.

Parent

Returns the next-higher object in Excel’s object hierarchy

Map Excel’s object hierarchy.

Name

Returns a string describing the object

Display information about an object or get a specific object from a collection.

You might be able to tell from Table 4-5 that the Name property is the most useful of the common members . Most (but not all) Excel objects have a Name property that identifies the object within its containing collection. For example, Worksheets("Sheet1") returns the worksheet with the Name property Sheet1.

That’s not true for all objects, however. The Range object, for instance, has an Address property instead of a Name property. Other objects, such as Window, use the Caption property, instead. Table 4-6 categorizes some of the common members that aren’t as universal as those listed in Table 4-5, but are actually more useful to know.

Table 4-6. Other useful, common members by category

Category

Member

Use to

General

Activate

Set focus on an object.

 

Caption

Set or return the text that appears in an object’s titlebar.

 

Value

Set or return the value displayed by an object. This is often the default property of an object.

Collections

Add

Create a new object and add it to the collection.

 

Count

Get the number of objects in a collection.

 

Index

Get the position of an object within a collection (use on the object, not the collection).

 

Item( )

Get an object by name or index from a collection. This is the default property of most collections.

 

Delete

Remove an object from a collection (use on the object, not the collection).

Appearance

Height

Set or return the height of an object in points. (There are 72 points in an inch.)

 

Left

Set or return the horizontal position of an object in points.

 

Top

Set or return the vertical position of an object in points.

 

Visible

Show or hide an object (True/False).

 

Width

Set or return the width of an object in points.

Printing

PrintOut

Print an object.

 

PrintPreview

View the object before printing.

The following sections explain using these common members.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required