How to obtain built-in constant values for an Office application

Summary

Microsoft Office applications can act as ActiveX Servers. They provide client applications design-time access to an Object library, or type library, that enables client applications to view an Office application's objects, properties, methods, and constants.

You can use late binding in a Visual Basic automation controller to automate an Office application without the need for referencing the Office application's type library. When you use late binding, you need to use the values for built-in constants for the Office application. This article describes how you can programmatically retrieve a list of built-in constants and the equivalent values at run time.

More Information

The following table illustrates which file contains the type library information:

ApplicationType Library
Microsoft Access 2000Msacc9.olb
Microsoft Binder 2000Msbdr9.olb
Microsoft Excel 2000Excel9.olb
Microsoft Graph 2000 Graph9.olb
Microsoft Office 2000Mso9.dll
Microsoft Outlook 2000Msoutl9.olb
Microsoft PowerPoint 2000Msppt9.olb
Microsoft Word 2000Msword9.olb
Microsoft Access 2002Msacc.olb
Microsoft Excel 2002Excel.exe
Microsoft Graph 2002Graph.exe
Microsoft Office 2002 MSO.dll
Microsoft Outlook 2002MSOutl.olb
Microsoft PowerPoint 2002MSPpt.olb
Microsoft Word 2002MSWord.olb
Microsoft Office Access 2003Msacc.olb
Microsoft Office Excel 2003Excel.exe
Microsoft Office Graph 2003Graph.exe
Microsoft Office 2003MSO.dll
Microsoft Office Outlook 2003MSOutl.olb
Microsoft Office PowerPoint 2003MSPpt.olb
Microsoft Office Word 2003MSWord.olb
Microsoft Office Access 2007Msacc.olb
Microsoft Office Excel 2007Excel.exe
Microsoft Office Outlook 2007MSOutl.olb
Microsoft Office PowerPoint 2007MSPpt.olb
Microsoft Office Word 2007MSWord.olb
Note The default location for these type libraries is:
Office VersionPath
Office 2000C:\Program Files\Microsoft Office\Office
Office XPC:\Program Files\Microsoft Office\Office10
Office 2003C:\Program Files\Microsoft Office\Office11
Office 2007C:\Program Files\Microsoft Office\Office12
To determine information about a type library at run time, use the TypeLibInformation ActiveX object (tlbinf32.dll) that ships with Visual Studio 6.0. The following sample illustrates how you can use TypeLibInformation to retrieve a list of built-in constants from a type library.

Steps to create the sample program

  1. Start Microsoft Visual Basic and create a new Standard EXE project. Form1 is created by default.
  2. From the Project menu, select References, and set a reference to tlbinf32.dll by checking the box containing TypeLib information.
  3. Place a CommandButton and two TextBoxes on the Visual Basic form.
  4. Select the second TextBox named Text2 by default, and in the Properties window, set the Multiline property to True. Set the Scrollbar property of Text2 to 2-Vertical.
  5. Copy the following code into the code window for Form1:
    Private Sub Command1_Click()
    Text1.Enabled = False
    Command1.Enabled = False
    Text2.Enabled = True
    GetWordConstants (Text1.Text)
    End Sub

    Private Sub GetWordConstants(strPath As String)
    Dim x As TypeLibInfo, sText as String

    On Error Resume Next
    'Get information from the Word Object library
    Set x = TypeLibInfoFromFile(Text1.Text)
    For Each r In x.Constants
    For Each mbr In r.Members
    sText = sText & mbr.Name & " = " & mbr.Value & vbCrLf
    Next mbr
    Next r
    Text2.Text = sText
    Set x = Nothing
    Text1.Enabled = True
    Command1.Enabled = True
    End Sub

    Private Sub Form_Load()
    Form1.WindowState = vbNormal
    Command1.Enabled = False
    Text1.Text = ""
    Text2.Text = ""
    Text2.Enabled = False
    End Sub

    Private Sub Text1_Change()
    If Text1.Text <> "" Then
    Command1.Enabled = True
    End If
    End Sub
  6. Run the project. Type in the full path of an Office Object Library file in the first TextBox and click the CommandButton to display type library information in the second TextBox.

References

Note Tlbinf32.exe is a file that contains the HTML Help file for the TypeLibInformation object. The Tlbinf32.dll file and the HTML Help file are provided for your reference only, and they are not supported by Microsoft.

For more information about using the TypeLibInformation object, please see the following articles in the Microsoft Knowledge Base:
224331 FILE: tlbinf32.exe : Help Files for tlbinf32.dll
172988 FILE: Programmatically Retrieve the Members of a DLL Class
Svojstva

ID članka: 239930 - posljednja izmjena: 23. ožu 2009. - verzija: 1

Povratne informacije