How To Obtain Built-In Constant Values for an Office Application (239930)



The information in this article applies to:

  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Access 2000
  • Microsoft Excel 2000
  • Microsoft Office Binder 2000
  • Microsoft Graph 2000
  • Microsoft Outlook 2000
  • Microsoft PowerPoint 2000
  • Microsoft Word 2000
  • Microsoft Access 2002
  • Microsoft Excel 2002
  • Microsoft Graph 2002
  • Microsoft Outlook 2002
  • Microsoft PowerPoint 2002
  • Microsoft Word 2002
  • Microsoft Office Access 2003
  • Microsoft Office Excel 2003
  • Microsoft Office PowerPoint 2003
  • Microsoft Office Outlook 2003
  • Microsoft Office Word 2003

This article was previously published under Q239930

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 Access 2003Msacc.olb
Microsoft Excel 2003Excel.exe
Microsoft Graph 2003Graph.exe
Microsoft Office 2003MSO.dll
Microsoft Outlook 2003MSOutl.olb
Microsoft PowerPoint 2003MSPpt.olb
Microsoft Word 2003MSWord.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

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


Modification Type:MinorLast Reviewed:7/1/2004
Keywords:kbAutomation kbhowto KB239930 kbAudDeveloper