Article ID: 147650 - Last Review: October 11, 2006 - Revision: 2.3 How To Navigate Excel Objects from Visual BasicThis article was previously published under Q147650 On This PageSUMMARY
This article explains three methods you can use to navigate and access
Microsoft Excel Application objects:
MORE INFORMATION
Each object in Microsoft Excel version 5.0 exists somewhere in the
application's hierarchy of objects. You choose among these objects by
navigating down that application's hierarchy. At the top of this hierarchy
is the Application object. Whatever events or actions you assign to the
Application object affect the entire application. For example:
Accessing Objects Using Longhand Reference or Default PropertiesEach workbook contains a collection of worksheets, each worksheet contains a collection of cells, and so on. (See the Microsoft Excel documentation and Help menu for specific details about Microsoft Excel's object hierarchy.) In code, references to a specific cell could look like this:Short CutsAll objects have a default property and method. For collections, the default method is the Item method. For most objects, the Name property is the default property. This convention was implemented to simplify programming. For example, the previous sample can be simplified to:Accessing Objects by Aliasing ObjectsYou can use aliasing to simplify object programming. If you were to write a lot of code that was manipulating Sheet1, for example, the syntax could become lengthy. To prevent this, create an object that points to the lowest common object. This is known as aliasing. Use the Set statement to create an alias:Accessing Objects by Using Parent and Application MethodsThe Parent and Application methods allow you to navigate back up the object hierarchy. The Application method navigates back to the application object, and the Parent method navigates up one level of the object hierarchy. All the examples in this article started with [Object]. As long as [Object] is a valid Microsoft Excel object, all of those statements are also valid. Regardless of the context of [Object].This is very helpful when programming the Microsoft Excel object from Visual Basic version 4.0. Microsoft Excel exposes only the three objects that can be used as entry points to Microsoft Excel. These are:
There is no exposed Workbook object, so there's no way to access the Workbook object directly. However, this is not a problem because the Parent method of a Worksheet or Chart object returns the Workbook object. The following example code illustrates this point. NOTE: oleExcel is an OLE control that contains an Excel.Sheet object. REFERENCES
Office Development Kit, Programming Integrated Solutions
APPLIES TO
| Article Translations
|

Back to the top
