Unable to terminate instance of EXCEL

Posted on 2011-10-25
Last Modified: 2012-05-12
I am running a procedure that updates workbooks from Excel.
After I save and close the workbook, I execute the following to terminate the instance of Excel:

On Error Resume Next
xlsApp.DisplayAlerts = False
Set xlsApp = Nothing
On Error GoTo 0
On Error GoTo ErrorHandler

Nothing happens.
I watch my Task Manager display as each of the above commands execute. There is only one instance of Excel in the stack, and nothing changes.
This is more than a little annoyance for me. I have another procedure which is trying to create an ADO connection object to an Excel workbook, and it won't work if there's an instance of Excel running.
How do I kill this beast?

Question by:shambalad
    LVL 61

    Expert Comment

    That part of your code looks okay...

    Can you post the entire function?  You need to ensure that those steps get executed at any exit point in the function (not necessarily just at the end)
    LVL 12

    Accepted Solution

    Very drastic, but this works:
    Sub Kill_Excel()

    Dim sKillExcel As String

    sKillExcel = "TASKKILL /F /IM Excel.exe"
    Shell sKillExcel, vbHide

    End Sub


    Hope this helps,
    LVL 92

    Assisted Solution

    by:Patrick Matthews
    We really need to see the whole procedure.

    My guess is that you have other Excel object variables, such as for range(s), worsheet(s), workbook(s), etc., and that those object variables are not being destroyed properly.
    LVL 7

    Author Comment

    Tried to award points and make a comment at the same time.....
    Matthew - I think you are probably right about some objects not being properly destroyed. I will be looking at that in the near future.
    In the meantime, though, Daniel's procedure really works like a charm.
    Thanks to all

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    This isn't a frequent question on EE. I must have seen it three or four times (among several thousand questions). However, I use this trick quite often, most frequently as a delayed Current event. A form does not expose it's calculation dependenc…
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now