Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

An api call to end an Excel process

An api call to end an Excel process

An api call to end an Excel process

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


RE: An api call to end an Excel process

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

If at first you don't succeed, skydiving is not for you.

RE: An api call to end an Excel process

One FAQ worth a look is  FAQ222-3383

Take Care

If at first you don't succeed, skydiving is not for you.

RE: An api call to end an Excel process

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

RE: An api call to end an Excel process

This is how I do it in Visual FoxPro:

oExcel = createobject('Excel.application')
oWbl = oExcel.workbooks.open('C:\Shared\Bsl.xls')

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.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close