Establishing a Reference to an Object Library

If you decide to use early binding to connect to another application via Automation, you should start by establishing a reference to the object library whose objects you are planning to manipulate. Follow these steps to create a reference to the Microsoft Word Object Library:

1. Activate the Visual Basic Editor window.

2. Select the current project in the Project Explorer window, and choose Tools | References.

3. In the References dialog box, choose the name of the application in the Available References list box. For this example, click the check box next to Microsoft Word 9.0 Object Library or Microsoft Word 10.0 Object Library (Figure 9-3). Scroll down in the Available References list box to locate this object library. If the type library for an object application that is installed on your computer doesn't appear in the list of available references, click the Browse button.

4. Click OK to close the References dialog box.

The References dialog box lists the names of the references that are available to your VBA project. The references that are not used are listed alphabetically. The references that are checked are listed by priority. For example, in Excel, the Microsoft Excel 10.0 Object Library has a higher priority than Microsoft Word 10.0 or 9.0 Object Library. When a procedure references an object, Visual Basic searches each referenced object library in the order in which the libraries are displayed in the References dialog box.

References - WoikWApplets

Available References:

VI Visual Basic For Applications VI Microsoft Excel 10,0 Object Library yiOLE Automation

¿¡Microsoft Office 10.1] Object LSrary

Vl Microsoft Access L 0.0 Object Library V! Microsoft PenPoint 9.0 Object Library r I Microsoft Forms Z.OCtiject Library

IVB&Project HvBAProject

_l IA5 Helper COM Component 1 rQ Type Library

• IA5RA[>ILr5 Protocol 1,0 Type lAraiy □!-} Vlde05cft V5PDF 7,0 Control I :-) VidecSoft V5Prir*er 7.0

Priority

Microscit Wad 9.0 Object Library

Location: C:\Pro3rarnFiles\MicrasoftOfflce\Office\M5WORD9.0lB Language: Standard

Figure 9-3:

In order to manipulate objects of another application, you should set a reference to the required object library.

After setting a reference to the required object library, you can browse the object properties and methods by using the Object Browser.

I UM f I

i J m

Library | Class

I Member

Classes

Members Qf"<g1obals>'

o |<globais>

-

ActiveDocument

H

«Sa Addin

—i

^ AcllvePrlnter

HI

Addlns

^ AcllveWindow

Adjustments

el1 Addlns

IS Application

eS* AnsweiWizard

¿51 AutoCaption

El? Application

AutoCaplions

eS* Assistant

IS AutoCorrect

AutoCaplions

¿9 AutoCorrectEntries

eI? AutoCorrect

ijSJ AutoCorrectEntiy

zi

EÜ* CaptionLabels

zi

LtorajyWw ti CjlProgram FiiestMerosott 0lNr:e'.0rii^ME^\r:PD3 0LB Microsoft Worn 3.Ü Ohjed Litjrary -

LtorajyWw ti CjlProgram FiiestMerosott 0lNr:e'.0rii^ME^\r:PD3 0LB Microsoft Worn 3.Ü Ohjed Litjrary -

Figure 9-4:

All of the Microsoft Word objects, properties, and methods can be accessed from a Microsoft Excel VBA project after adding a reference to the Microsoft Word 9.0 Object Library (see Figure 9-3).

0 0

Responses

  • emilia
    How to automatically reference the microsoft word object library?
    8 years ago

Post a comment