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 <[email protected]>
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")
> endwith
>
> Catch to oError
>
> lOK = .f.
>
> MessageBox(oError.message,16,'Excel caused an error',2000)
>
> thisform.oExcel.quit
>
> EndTry
>
> if not lOK
>
> quit
>
> else
>
> *** show the spreadsheet
>
> endif
>
> 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]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/cag1nny95erbknuu+r6hj93knjnmigecytxnef1bvp+z0uyq...@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.