Microsoft KB Archive/239930

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

Article ID: 239930

Article Last Modified on 3/29/2007

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Office Binder 2000
 * Microsoft Graph 2002
 * Microsoft Graph 2000
 * Microsoft Office Access 2007
 * Microsoft Office Access 2003
 * Microsoft Access 2002 Standard Edition
 * Microsoft Access 2000 Standard Edition
 * Microsoft Office Outlook 2007
 * Microsoft Office Outlook 2003
 * Microsoft Outlook 2002 Standard Edition
 * Microsoft Outlook 2000 Standard Edition
 * Microsoft Office PowerPoint 2007
 * Microsoft Office PowerPoint 2003
 * Microsoft PowerPoint 2000 Standard Edition
 * Microsoft PowerPoint 2002 Standard Edition
 * Microsoft Office Word 2007
 * Microsoft Office Word 2003
 * Microsoft Word 2002 Standard Edition
 * Microsoft Word 2000 Standard Edition
 * Microsoft Office Excel 2007
 * Microsoft Office Excel 2003
 * Microsoft Excel 2002 Standard Edition
 * Microsoft Excel 2000 Standard Edition

-



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:

Note The default location for these type libraries is:

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
 Start Microsoft Visual Basic and create a new Standard EXE project. Form1 is created by default. From the Project menu, select References, and set a reference to tlbinf32.dll by checking the box containing TypeLib information. Place a CommandButton and two TextBoxes on the Visual Basic form. 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.  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  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.</ol>

<div class="references_section">