Article ID: 147573
Article Last Modified on 9/24/2003
oleApp = GETOBJECT(,"Excel.Application")However, with Microsoft Excel version 7.0, this command can cause the following error even if Microsoft Excel is running:
CREATEOBJECT("Excel.Application"))
* Start sample code
* Main program code
oleExcel = findxl()
IF TYPE("oleExcel") = "N"
=MessageBox("No instances of Excel running !")
ELSE
oleExcel.WindowState = -4137 &&maximize Excel
ENDIF
FUNCTION findxl
DECLARE LONG FindWindowA IN USER32 AS FindA STRING,STRING
DECLARE LONG SendMessageA IN USER32 AS SendA LONG, LONG, LONG, LONG
WM_USER = 1024
PRIVATE myExcelApp
PRIVATE mySendMessage
hwnd = FindA("XLMAIN", 0)
IF hwnd = 0 then
RETURN 0
ELSE
mySendMessage = SendA(hwnd, WM_USER + 18, 0, 0)
myExcelApp = GetObject(, "Excel.Application")
RETURN myExcelApp
ENDIF
If you are using Microsoft Office 2000 or Microsoft Office XP, change the following: mySendMessage = SendA(hwnd, WM_USER + 18, 0, 0)to the following:
mySendMessage = SendA(hwnd, WM_ACTIVATEAPP, 0, 0)For additional information about using the GETOBJECT() function to reference Microsoft Excel, click the following article numbers to view the articles in the Microsoft Knowledge Base:
132535 Releasing Object Variable Does Not Close Microsoft Excel
128994 Behavior of GETOBJECT()With Excel and Word For Windows
Additional query words: VFoxWin kbinf CREATEOBJECT OLE automation
Keywords: kbprb kbcode KB147573