An api call to end an Excel process
An api call to end an Excel process
(OP)
Hi,
I have code that opens Excel and inputs data, but some times it gets hung up because Excel is left runing in the backround. ANd my code has xl1.ActiveWorkbook.Save
xl1.Quit which seems to do nothing.
Is there any way to kill the the excel process, before I run my code, that may be left runing in the task Manager. I hope no one mines I had posted this in the VBA forum as well, but they do not seem to think that is an API call that would do this; but I thought that I once saw one.
Thank You
I have code that opens Excel and inputs data, but some times it gets hung up because Excel is left runing in the backround. ANd my code has xl1.ActiveWorkbook.Save
xl1.Quit which seems to do nothing.
Is there any way to kill the the excel process, before I run my code, that may be left runing in the task Manager. I hope no one mines I had posted this in the VBA forum as well, but they do not seem to think that is an API call that would do this; but I thought that I once saw one.
Thank You
ITM
RE: An api call to end an Excel process
I would be immensely *********** off with you & your software if it arbitarily decided to shut down a copy of excel, without warning and probably in a rather dirty fashion.
That being said, perhaps you could use an already running instance of Excel by calling getobject and examining your return value before Using CreateObject to create another instance.(you will need to use late binding).
I would also suggest that you look at you code closely to see why the XL object is still in existence. There are a number of gotcha's with automation of XL that you need to investigate (explicit creation and release of objects & subobjects for example). I am sure that there is an excellent FAQ either in the VBA or VB forums on Excel automation.
IMHO trying to use an API to brute force kill the object is not solving the problem, just covering it up
Take Care
Matt
If at first you don't succeed, skydiving is not for you.
RE: An api call to end an Excel process
Take Care
Matt
If at first you don't succeed, skydiving is not for you.
RE: An api call to end an Excel process
For example: if you create a new workbook object, you should know that Excel automatically creates three worksheet objects for you as children of the workbook. You need to set those sheets to Nothing before setting the workbook object to Nothing.
Failure to do this (in this order) means you will have orphaned some objects, and Excel won't close itself if it thinks that any objects are still in use.
BTW, this is a better question for the VBA or Visual Basic forums.
Chip H.
____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
RE: An api call to end an Excel process
RE: An api call to end an Excel process
oExcel = createobject('Excel.application')
oWbl = oExcel.workbooks.open('C:\Shared\Bsl.xls')
oExcel.WINDOWS("Bsl.xls").ACTIVATE
OExcel.ROWS("2:32000").SELECT
oExcel.SELECTION.DELETE
oExcel.Visible = .T.
* Destroy the Automation object variable
oExcel = Null
The trick is the last line: oExcel = Null
If you want the VBA code, open Excel. Under Tools/Macros select Record new macro. Then open your file, close it and print the macro.
Pat