I use the following
PARAMETERS whatprg, justchecking
lcProcess=whatprg+".EXE" lcComputer = "." loWMIService = GETOBJECT("winmgmts:" + "{impersonationLevel=impersonate}!\" + lcComputer + "\root\cimv2") colProcessList = loWMIService.ExecQuery ("Select * from Win32_Process")
IF TYPE('colProcessList') = "O" FOR EACH loProcess IN colProcessList IF ALLTRIM(UPPER(loProcess.NAME)) == ALLTRIM(UPPER(lcProcess)) IF justchecking iamopen=.t. EXIT endif trt=MESSAGEBOX("Is it ok to close "+lcProcess+" ?",4+32,'') IF trt=6 loProcess.TERMINATE() exit ENDIF NEXT ENDIF && IF TYPE('colProcessList') = "O"
RELEASE colProcessList, loWMIService
On Sat, Oct 22, 2016 at 9:59 AM, rafael copquin rcopquin@fibertel.com.ar wrote:
I have been using Excel automation for years. However, I could not find a way to kill the Excel application when an error occurs.
Here is an example:
I have this cursor with an inventory list that contains 9000 rows and 10 columns, named curStock.
I save the cursor with:
local cExcel
cExcel = 'c:\temp\stock.xls'
select curStock
copy to (cExcel) type xl5
if upper(vartype(thisform.oExcel)) = "O" thisform.oExcel.quit thisform.oExcel = .f. Else thisform.AddProperty('oExcel') EndIf
if upper(vartype(thisform.oExcel)) <> "O" thisform.oExcel=createobject("Excel.Application") else thisform.oExcel=getobject(,"Excel.Application") endif
Try
lOK = .t. With thisform.oExcel .workbooks.open("&cExcel") endwithCatch to oError
lOK = .f.
MessageBox(oError.message,16,'Excel caused an error',2000)thisform.oExcel.quit
EndTry
if not lOK
quitelse
*** show the spreadsheetendif
The property thisform.oExcel is trying to open the big Excel sheet (stock.xls) but fails
Supposedly thisform.Excel.quit should kill the Excel instance.
However it still remains in memory. The task manager shows it is still dangling in memory but is invisible.
How can I kill it?
BTW I use this approach instead of filling and formatting the sheet line by line, because it takes about half an hour to show, due to the large amount of records the cursor contains.
Rafael Copquin
[excessive quoting removed by server]