Instead of trying to open your XLS file via Excel Automation, just try opening it via a ShellExecute call.
hth, --Mike
On 2016-10-21 16:59, rafael copquin 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]