DOCUMENT:Q285396 13-JUN-2001 [foxpro] TITLE :HOWTO: Obtain Office Constants from .OLB Files with VFP PRODUCT :Microsoft FoxPro PROD/VER::6.0 OPER/SYS: KEYWORDS:kbAutomation kbCOMt kbvfp600 kbGrpDSFox kbDSupport kbCodeSnippet ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual FoxPro for Windows, version 6.0 ------------------------------------------------------------------------------- SUMMARY ======= Automation of Microsoft Office products from Visual FoxPro (VFP) is a popular undertaking for VFP developers. Most often, VFP developers approach this task by converting macros from the product to be automated or by translating examples written for Microsoft Visual Basic. Regardless of the approach, the VFP developer must often convert Office constants to their literal values before these constants can be used from VFP. Depending on the amount of code, this can be a tedious undertaking. MORE INFORMATION ================ The following sample code helps VFP developers translate Office constants. It provides a method to extract the built-in constants from Office object library (.olb) files, and then allows the developer to save them to a header (.h) file for inclusion in a VFP project. For example, a VFP developer writing a program to automate Microsoft Word can use this code to extract all of the Word constants to a header file. The header file can be included in the Word automation program using the #INCLUDE statement, allowing the developer to use Word constants "as is" in the VFP code (for example, the developer can use wdFindContinue instead of its literal value of 1). To use this sample code, follow these steps: 1. Paste the code below in a new .prg file, and then save and run the program. A form with the title ".OLB Constants Extractor" appears. 2. Click the ellipsis (...) button to locate an .olb file in your Office folder, and then click Extract Constants. The form extracts all the constants from the .olb file you selected and writes them to the edit box. 3. You can then review the output or save the results to a header file for use in your code. To do this, click Save to .h. Office constants are available from the following files: +-------------------------------------------------------+ | Office 2000 Component | File Containing Constants | +-------------------------------------------------------+ | Microsoft Word 2000 | MSWord9.olb | +-------------------------------------------------------+ | Microsoft Excel 2000 | Excel9.olb | +-------------------------------------------------------+ | Microsoft Access 2000 | MSAcc9.olb | +-------------------------------------------------------+ | Microsoft PowerPoint 2000 | MSPPT9.olb | +-------------------------------------------------------+ | Microsoft Outlook 2000 | MSOutl9.olb | +-------------------------------------------------------+ | Microsoft Graph 2000 | Graph9.olb | +-------------------------------------------------------+ | Microsoft Binder 2000 | MSBdr9.olb | +-------------------------------------------------------+ NOTE: This sample code uses objects that are included in the Tlbinf32.dll file. This dynamic-link library (.dll) file ships with Microsoft Visual Studio 98 Service Pack 4. If this file is not present and properly registered on your computer, the sample code below will fail. ****************START CODE**************** PUBLIC oform1 oform1=NEWOBJECT("form1") oform1.SHOW RETURN ****************FORM CODE**************** DEFINE CLASS form1 AS FORM HEIGHT = 445 WIDTH = 567 DOCREATE = .T. AUTOCENTER = .T. BORDERSTYLE = 1 CAPTION = ".OLB Constants Extractor" MAXBUTTON = .F. MINBUTTON = .F. NAME = "Form1" ADD OBJECT txtolbfile AS TEXTBOX WITH ; HEIGHT = 27, ; LEFT = 65, ; READONLY = .T., ; TABINDEX = 2, ; TOP = 6, ; WIDTH = 458, ; NAME = "txtOLBFILE" ADD OBJECT label1 AS LABEL WITH ; AUTOSIZE = .T., ; CAPTION = ".\