On Mon, Jun 14, 2010 at 9:36 AM, Rafael Copquin <[email protected]> wrote:
> I read Microsoft Office Automation with Visual FoxPro by Tamar Grainor
> and others, ages ago, and it has been very useful to me over the years.
>
> However, there is something I could never get to work and it is this:
>
> suppose that for some reason an error occurs in your application while
> the Excel object has been instantiated and the worksheet is not visible.
>
> IOW, I write code like this:
>
> thisform.oExcel=createobject("Excel.Application")
>
> a cursor is scanned, its records are placed in a worksheet and when
> everything is done, I issue the command:
>
> thisform.oExcel.visible = .t.
>
> But, if an error occurs while scanning the cursor, the form has code to
> exit immediately from VFP, sending the error message to an error log, etc.
>
> However, the Excel object is standing there and, because it is not
> visible, the user is not aware of this. Subsequent calls to the Excel
> method in the form will not work, depending on the Excel version the
> user has installed in his/her machine and he could end up having two or
> more instances of Excel dangling in memory, pus her machine "frozen".
>
> I try to issue this command:
>
> if pemstatus(thisform,'oExcel',5) = .t. && the excel property exists
> if vartype(thisform.oExcel) = 'O' && Excel is instatiated and alive
> thisform.oExcel.quit()
> endif
> endif
>
> But it does not work, it does not kill the Excel instance. It has to be
> done by hand using the Windows Task Manager.
>
> How should I code the error routine to kill the Excel instance when
> there is any error (Excel generated or form generated) ?
-----------------
Can you write a try catch for your error handler?
try
thisform.oExcel=createobject("Excel.Application")
scan
* code here
endscan
end try
catch
release the oExcel object here
write to your existing log
end catch
finally
* any code here
>
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/[email protected]
** 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.