HOWTO: Obtain Built-In Constant Values for an Office Application
ID: Q239930
|
The information in this article applies to:
-
Microsoft Office 2000
-
Microsoft Visual Basic Professional and Enterprise Editions for Windows, versions 5.0, 6.0
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 Object library files for Microsoft 2000 applications are as follows:
Microsoft Excel 2000 |
Excel9.olb |
Microsoft Word 2000 |
MSWord9.olb |
Microsoft Outlook 2000 |
MSOutl9.olb |
Microsoft PowerPoint 2000 |
MSPpt9.olb |
Microsoft Access 2000 |
MSAcc9.olb |
Microsoft Graph 2000 |
Graph9.olb |
Microsoft Binder 2000 |
MSBdr9.olb |
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
If Right(strPath, 3) <> "olb" Then
MsgBox "Incorrect file extension, please re-enter."
Exit Sub
End If
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
Text2.Text = Text2.Text & mbr.Name & " = " & mbr.Value & vbCrLf
Next mbr
Next r
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.
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:
Q224331 FILE: tlbinf32.exe : Help Files for tlbinf32.dll
Q172988 FILE: Programmatically Retrieve the Members of a DLL Class
Additional query words:
bultin built-in constants
Keywords : kbAccess kbAutomation kbExcel kbOutlook kbPowerPt kbWord kbGrpDSO kbDSupport
Version : WINDOWS:2000,5.0,6.0
Platform : WINDOWS
Issue type : kbhowto