Object Inspection Using the Object Browser

When you develop in Excel with VBA, your programmatic interaction with Excel consists of manipulating or using Excel's various objects. Excel has many, many objects available for you to manipulate. Without any other information, you can probably surmise that a worksheet object represents worksheets and a workbook object represents workbooks. One way you can see what other objects are available is to use the Object Browser. An example of the Object Browser is shown in Figure 2.12. To display the Object Browser, press F2 or select View ^ Object Browser.

You can use the Object Browser to view information for all object libraries, a specific object library, or your own project. By information, I mean a list of all the objects in the library, and for each object, a list of the object's members. An object library is a set of objects that are related in some way. For example, an object library for Excel contains all of the objects in Excel. An example of this is shown in Figure 2.13.

If you look on the right side of the window in Figure 2.13, you can see all of the members of the Worksheet object. The flying cube icons signify that the member is a method, the lightning bolt indicates that the member is an event, and the index card denotes the member as a property. I'll discuss the meaning of these terms later in the book.

If you want to know more information about either the object or one of its members, select the item and either press F1 or click the question mark icon. This will open up the Help topic associated with the object.

Figure 2.12

Using the Object Browser is a great way to take inventory of the various objects available for programmatic manipulation.

k Object Browser

mm

| — j TJ

- #4 ^

Classes

Members of '«globals>'

o ;<aiobais>

^ Abs

a

Addin

AcliveCell

& Ad dins

AetiveChart

jj£| Adjuslments

id? ActivePrinler

® All owe d ¡(Range

& AeliveSheeJ

iS AllowEdltRanges

eSP AcllveWlndow

US AnswatWizard

E© AetiveWorfcbook

AnswerWizardFiles

ESP Addins

Application

^ AppActivate

£3 Areas 1*1 V

El? Application

<aii Libraries*

OBJECT INSPECTION USING THE OBJECT BROWSER 25

Figure 2.13

By changing the library to Excel, you can view all of the objects in the Excel object library. As you can see, sure enough, there is a Worksheet object.

Figure 2.13

By changing the library to Excel, you can view all of the objects in the Excel object library. As you can see, sure enough, there is a Worksheet object.

k Object Browser

| Excel

- < ■

-J _iJ

J_

Ä

jd

Classes

Members of Worksheet'

£3 Window

Ai

^ Activate

A

Windows

P Activate

Workbook

eI? Application

Workbooks

& AutoFilter

IM] worksheet

ü®1 AutoFilterMode

jiS WorKsheetF unction

p BeforeDoutueCIIcK

Iq^j Worksheets

p BeforeRightClick

li^ XlApplicationtntemational

ä Calculate

# XIApptyNamesOrder

p Calculate

iP XlArabitModes

«1

& Cells

v.

Class Worksheet

Mentoer oi focel

You can use the Object Browser to quickly take inventory of your own project.

Figure 2.14

You can use the Object Browser to quickly take inventory of your own project.

Take Your Own Inventory

In addition to providing a way to view the Excel object model, the Object Browser also has the capability to provide you with information regarding your own project. If you are working on a large project, the Object Browser can be a convenient way to get a quick overview of all of the components of a project. Further, if you want to investigate a particular procedure in more detail, you can right-click it and choose View Definition. This quickly transfers you to where the procedure is located. Figure 2.14 shows an example of how you can use the Object Browser to view the items in a project.

Figure 2.15

The Object Browser can be handy for locating objects of interest.

Figure 2.15

The Object Browser can be handy for locating objects of interest.

0 0

Responses

  • leah
    How to create inspect in vba?
    8 months ago

Post a comment