That's become a standard part of my exception handling with COM stuff. If I catch any kind of error, I check to see if the Word or Excel object is in scope and make it visible.
--
rk -----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of rafael copquin Sent: Friday, October 21, 2016 5:36 PM To: profoxtech@leafe.com Subject: Re: Excel errors
I solved it!
What I did was make the oExcel object _visible_ just after instantiation and before trying to open the file.
if upper(vartype(thisform.oExcel)) <> "O" thisform.oExcel=createobject("Excel.Application") else thisform.oExcel=getobject(,"Excel.Application") endif
thisform.oExcel.visible = .T.
Try
lOK = .t.
With thisform.oExcel .workbooks.open("&cExcel") endwith
etc
Thank you all anyways
Rafael
On 21/10/2016 18:09, Richard Kaye wrote:
You've probably got some hidden dialog waiting for an answer asking you if you want to save your changes. Try adding something like this to your exception handling before you call Quit.
m.oExcel.ActiveWorkbook.Saved= .T. && this prevents Excel prompt when we destroy the Excel object
--
rk -----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of rafael copquin Sent: Friday, October 21, 2016 4:59 PM To: profoxtech@leafe.com Subject: Excel errors
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.quitEndTry
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]