Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

An api call to end an Excel process 1

Status
Not open for further replies.

itmasterw

Programmer
Apr 13, 2003
147
US
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


ITM
 
Think very carefully about what you are asking for...

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.
 
One FAQ worth a look is faq222-3383

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Failure of a MS-Office app to close down is caused 99.9% of the time by the developer failing to close all the objects that Excel (or Word, etc) created on their behalf.

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
 
This is how I do it in Visual FoxPro:

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top