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
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") 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]
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]
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]
On 2016-10-21 18:28, Richard Kaye wrote:
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.
Understandable, but the processing runs faster if it's invisible, right?
I think that there are some posts on Fox Wiki that suggest the opposite.
Laurie
On 23 October 2016 at 20:16, mbsoftwaresolutions@mbsoftwaresolutions.com wrote:
On 2016-10-21 18:28, Richard Kaye wrote:
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.
Understandable, but the processing runs faster if it's invisible, right?
[excessive quoting removed by server]
That's been my experience. I don't make the object visible until it's ready for presentation to the end user. But if an error occurs during processing and gets trapped by the try..catch, I can make sure the user is notified and make the COM object visible at the point where no more processing is happening.
--
rk -----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of mbsoftwaresolutions@mbsoftwaresolutions.com Sent: Sunday, October 23, 2016 3:16 PM To: profoxtech@leafe.com Subject: RE: Excel errors
On 2016-10-21 18:28, Richard Kaye wrote:
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.
Understandable, but the processing runs faster if it's invisible, right?
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]
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]