How To Convert VBA to FoxPro for OLE AutomationLast reviewed: November 27, 1996Article ID: Q160064 |
The information in this article applies to:
SUMMARYIn order to perform OLE Automation with an application that uses Visual Basic for Applications (VBA), it is important to understand how to convert the VBA syntax for each command or function into a syntax that may be used in Visual FoxPro. Below is a list of a few of the most common Visual Basic for Applications (VBA) commands that may be used to perform OLE Automation from Visual FoxPro to Microsoft Excel or Microsoft Word along with the appropriate syntax for use in Visual FoxPro. Since this list is very limited, it may be helpful to understand some of the points of converting VBA to FoxPro:
For a description of the methods and statements listed, along with information about the use of specific parameters, please see the respective Visual Basic Reference file for Microsoft Word or Microsoft Excel.
MORE INFORMATION
General NotesVariables and parameters are prefixed by a single character indicating the type of the variable or parameter as follows:
VBA has many built-in constants that may be used. However, FoxPro does not know the values of these constants. To use them in FoxPro, you need to define them as constants in the scope of your FoxPro program or form, or replace them with their appropriate values.
Object VariablesoWord is the variable used to reference Microsoft WordBasic objects, created with the following command:
oWord = CREATEOBJECT("Word.Basic")oXL is the variable used to reference Microsoft Excel application objects, created with the following command:
oXL = CREATEOBJECT("Excel.Application")oXLSheet is the variable used to reference Microsoft Excel worksheet objects, created with one of the following command:
oXLSheet = CREATEOBJECT("Excel.Sheet") -or- oXLSheet = oXL.ActiveSheetoXLBooks is the variable used to reference Microsoft Excel Workbooks Collection objects, created with the following command:
oXLBooks = oXL.WorkbooksoXLWkBook is the variable used to reference Microsoft Excel workbook objects, created with the following command:
oXLWkBook = oXL.ActiveWorkBook Directory/File Management StatementsAdd Method (Microsoft Excel)
Syntax: oXLBooks.Add([cTemplate]) oXLSheet.Add([cBefore [, cAfter [,nCount [, nType]]]]) oXLSheet.Add([oBefore [, oAfter [,nCount [, nType]]]])Cells Method (Microsoft Excel)
Syntax: oXL.Cells([nRowIndex [, nColumnIndex]]) oXLSheet.Cells([nRowIndex [, nColumnIndex]])ChDir Method (Microsoft Word)
Syntax: oWord.ChDir(cPath) Example: oWord.ChDir("C:\MY DOCUMENTS")Close Method (Microsoft Excel)
Syntax: oXLBooks.Close() oXLWkBook.Close([lSaveChanges [, cFileName [, lRouteWorkbook]]])FileClose Method (Microsoft Word)
Syntax: oWord.FileClose([nSave])FileCloseAll Method (Microsoft Word)
Syntax: oWord.FileCloseAll([nSave])FileNew Method (Microsoft Word)
Syntax: oWord.FileNew([cTemplate [, nNewTemplate]]) Example: oWord.FileNew("C:\MY DOCUMENTS\MYTEMPLATE.DOT")FileNewDefault Method (Microsoft Word)
Syntax: oWord.FileNewDefault()FileOpen Method (Microsoft Word)
Syntax: oWord.FileOpen(cName [, nConfirmConversions [, nReadOnly ; [, nAddToMru [, cPasswordDoc [, cPasswordDot [, nRevert ; [, cWritePasswordDoc [, cWritePasswordDot]]]]]]]]) Example: oWord.FileOpen("C:\MY DOCUMENTS\MYWORD.DOC")Open Method (Microsoft Excel)
Syntax: oXLBooks.Open(cFileName [, nUpdateLinks [, lReadOnly [, nFormat ; [, cPassword [, cWriteResPassword [, lIgnoreReadOnlyRecommended ; [, nOrigin [, cDelimiter [, lEditable [, lNotify ; [, nConverter]]]]]]]]]]]) Example: oXLBooks.Open("C:\MY DOCUMENTS\MYSHEET.XLS")Value Property (Microsoft Excel)
Syntax: object.Value = NewValue Example: oXL.ActiveWindow.ActiveCell.Value = "Hello" |
KBCategory: kbinterop kbhowto
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |