Using the Object Browser

While writing your Visual Basic procedures, you might want to see what objects are available in the active workbook, including the names of procedures you've already written. You can look at this information using the Object Browser.

The Object Browser performs three important functions:

To display the Object Browser

Object Browser button

You can also click the Object Browser button on the Visual Basic toolbar or press F2 from within a module.

What Appears in the Object Browser

The Object Browser dialog box displays either of two sets of information:

The Object Browser contains a box that lists the names of all the object libraries and all the workbooks referenced by the workbook that contains the module you're creating. An object library is a file or a part of an application that provides Visual Basic with information about objects. Libraries and workbooks identify the objects you can use in your procedures. For more information about references to libraries and workbooks, see "Creating a Reference to a Workbook" in Chapter 1.

The list in the Libraries/Workbooks box includes:

Below the Libraries/Workbooks box is the Objects/Modules box. The contents of this box depend on whether the selection in the Libraries/Workbooks box is an object library name or a workbook name, as described in the following table.

>

If the Libraries/Workbooks box shows

>

The Objects/Modules box shows

>

>

The name of an object library

>

The available objects in the library, or the categories of available functions

>

The name of a workbook

>

The names of all the modules in the workbook


To the right of the Objects/Modules box is the Methods/Properties box. The contents of this box depend on whether the items listed in the Objects/Modules box are the objects in a library or the modules in a workbook, as described in the following table.

>

If the Objects/Modules box shows

>

The Methods/Properties box shows

>

>

The objects in an object library

>

The properties and methods of each object in the library

>

The modules in a workbook

>

The names of the procedures in each module, including property procedures


Moving Between Procedures

You can use the Object Browser to move quickly from one procedure in a workbook to another.

To move to a procedure in a workbook

1. Switch to a Visual Basic module.

2. On the View menu, click Object Browser.

3. In the Libraries/Workbooks box, click the name of the workbook that contains the procedure you want to use.

4. In the Objects/Modules box, click the name of the module that contains the procedure you want.

5. In the Methods/Properties box, click the name of the procedure.

6. Click Show.

The Object Browser moves you to the module that contains the procedure you selected. The insertion point appears to the left of the line immediately following the procedure declaration line.

Browsing Objects

You can also use the Object Browser to see:

To find the properties and methods of objects

1. On the View menu, click Object Browser.

2. In the Libraries/Workbooks box, click the name of the object library you want to browse or that contains the object you want to use.

3. In the Objects/Modules box, click the name of the object for which you want to see properties and methods.

Pasting Code

When you finish using the Object Browser to find an object with a property or method you want to use, you can paste a fragment of Visual Basic code from that property or method into your procedure. You can then edit the code fragment to fit the needs of your procedure. The Object Browser pastes the code fragment at the insertion point in the active module.

The code fragment includes syntax for named arguments when appropriate. After you paste the code fragment into your procedure, you can delete any arguments you don't need and then add the appropriate values for the arguments you want to use.

To paste a code fragment into a procedure

1. In a Visual Basic module, place the insertion point at the location in the code where you want to paste the code fragment.

2. On the View menu, click Object Browser.

3. In the appropriate boxes, click the library and the object whose property or method you want to use.

4. In the Methods/Properties box, click the property or method you want to paste into the procedure.

5. Click Paste.