Excel Is an Object?

You’ve used Excel for quite a while, but you probably never thought of it as an object. The more you work with VBA, the more you view Excel in those terms. You’ll understand that Excel is an object and that it contains other objects. Those objects, in turn, contain still more objects. In other words, VBA programming involves working with an object hierarchy.

At the top of this hierarchy is the Application object — in this case, Excel itself (the mother of all objects).

Climbing the Object Hierarchy

The Application object contains other objects. Following is a list of some of the more useful objects contained in the Excel Application:

✓ Addin
✓ Window
✓ Workbook
✓ WorksheetFunction

Each object contained in the Application object can contain other objects. For example, the following is a list of objects that can be contained in a Workbook object:

✓ Chart
✓ Name
✓ VBProject
✓ Window
✓ Worksheet

In turn, each of these objects can contain still other objects. Consider a Worksheet object, which is contained in a Workbook object, which is contained in the Application object. Some of the objects that can be contained in a Worksheet object are:

✓ Comment
✓ Hyperlink
✓ Name
✓ PageSetup
✓ PivotTable
✓ Range

Put another way, if you want to do something with a range on a particular worksheet, you may find it helpful to visualize that range in the following manner:

Range➪contained in Worksheet➪contained in Workbook➪contained in Excel

Is this beginning to make sense?

Figure 4-1 shows part of Excel’s Object Model Map. If you really want to be overwhelmed, display the VBA Help system and search for object model map. It’s a huge diagram that lists all objects, and each one is clickable so you can read all about it.

Figure 4-1: Visualizing a part of the Excel object model.
Figure 4-1: Visualizing a part of the Excel object model.

Yes folks, Excel has more objects than you can shake a stick at, even old-timers like me can get overwhelmed. The good news is that you’ll never have to actually deal with most of these objects. When you’re working on a problem, you can just focus on a few relevant objects — which you can often discover by recording a macro.

megjegyzés0

Post a Comment

 
© 2013 Excel 2007 Manual | Blogger.com
Template Modify by Panjz Online Template by Creating Website