none
Excel.exe still runs in the background after quitting RRS feed

  • Question

  • Hi All,

    I am using Word VBA to automatically update data and charts in Excel files. However, after I quit the application, I can still see Excel.exe running in the background. But this does not affect me from running the macro again. Each time I run, a new Excel.exe will stay in the background. I googled this problem and it seemed like there is a reference problem somewhere. Has anyone encountered similar problems before?

    Below is a simplified version of the problem:

    Sub test()
        Dim exApp As Excel.Application
        Set exApp = CreateObject("Excel.Application")
        exApp.Quit
        Set exApp = Nothing
    End Sub

    Thank you for your help

    Monday, December 31, 2012 9:22 AM

Answers

  • When I run the macro

    Sub test()
        Dim exApp As Excel.Application
        Set exApp = CreateObject("Excel.Application")
        exApp.Quit
        Set exApp = Nothing
    End Sub

    in Word, Excel.exe appears briefly in the Processes tab of Task Manager, but it disappears at the end of the macro, as it should.

    If you keep having problems, restart Windows to see if the problem persists.


    Regards, Hans Vogelaar

    Monday, December 31, 2012 10:39 AM

All replies

  • I hope that the simplified version doesn't leave an instance of Excel running.

    When you automate one application from the other, you must take great care to let ALL objects in the "called" application refer directly or indirectly to the application object that you created. The problem is usually caused by using an object that does NOT refer to the application object.

    For example, the following is OK:

    Sub test()
        Dim exApp As Excel.Application
        Dim exWbk As Excel.Workbook
        Set exApp = CreateObject("Excel.Application")
        Set exWbk = exApp.Workbooks.Add
        ...

    The variable exWbk refers to exApp through its Workbooks collection.

    The following is not OK:

    Sub test()
        Dim exApp As Excel.Application
        Dim exWbk As Excel.Workbook
        Set exApp = CreateObject("Excel.Application")
        Set exWbk = Workbooks.Add
        ...

    The variable exWbk does NOT refer to exApp, and because of that, it will probably cause an extra instance of Excel to be created; this extra instance is not controlled by your macro and will remain in memory.

    Check your code carefully for such things.


    Regards, Hans Vogelaar

    Monday, December 31, 2012 10:12 AM
  • Hi Hans,

    I didn't seem to have the error you mentioned above. When I open excel files I used:

    Set exWbk = exApp.Workbooks.Open(myPath)

    The code i quoted above shows the same problem. It does not open any workbook at all. Just open and close an Excel Application cause the Excel.exe running in the background.

    Do you have the same problem when you run the code I have above?

    Thanks

    Monday, December 31, 2012 10:33 AM
  • When I run the macro

    Sub test()
        Dim exApp As Excel.Application
        Set exApp = CreateObject("Excel.Application")
        exApp.Quit
        Set exApp = Nothing
    End Sub

    in Word, Excel.exe appears briefly in the Processes tab of Task Manager, but it disappears at the end of the macro, as it should.

    If you keep having problems, restart Windows to see if the problem persists.


    Regards, Hans Vogelaar

    Monday, December 31, 2012 10:39 AM
  • Hi Forestrock

    In addition to what Hans suggests, you might make the exApp.Visible = True so that you can see if it's expecting some kind of interaction with you (message).

    When Excel is started via automation it should not be loading any add-ins that would conflict with what you're doing, but it may still be a good idea to check what's actually going on...

    You might also try using Set exApp = New Excel.Application instead of using CreateObject.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, December 31, 2012 1:07 PM
    Moderator
  • You are absolutely right. When I run the Macro in another computer, the problem is gone.

    Thanks Hans.

    Friday, January 4, 2013 3:37 AM