Microsoft Office Excel has encountered a problem and needs to close.

Answered Microsoft Office Excel has encountered a problem and needs to close.

  • Tuesday, June 22, 2010 5:26 AM
     
     

    Hi,

    I am developing an excel 2003 VSTO add-in in Visual Studio 2008. Once the add-in is loaded , then when I close exce, I am getting this error

    Microsoft Office Excel has encountered a problem and needs to close.We are sorry for the inconvenience.

    My code in ThisAddin_ShutDown is

    Globals.ThisAddin.Application.Quit();

    Globals.ThisAddin.Application = null;

    GC.Collect();

     

     

All Replies

  • Tuesday, June 22, 2010 5:47 AM
    Moderator
     
     

    You do NOT need the code you show in ThisAddin_Shutdown. You should not be sending Excel the command to quit from within your add-in. Your add-in requires Excel to be running in order to shutdown. If you've already given Excel the command to exit, as an end-user, your add-in should not be doing this, as well.

    There is no need for you to set the application to null. VSTO takes care of this for you.

    There is no need to trigger garbage collection. Again, VSTO takes care of this.


    Cindy Meister, VSTO/Word MVP
  • Tuesday, June 22, 2010 6:31 AM
     
     

    Thanks. But I am still getting the error while closing excel.

     

  • Tuesday, June 22, 2010 6:40 AM
    Moderator
     
     

    Did you test this in your development environment in Debug mode (pressing F5) or in another way?

    If during Debug mode, then we can be sure that changes you made were recognized by Excel. In that case, you need to provide more information about what your add-in is doing.

    One other thing important thing is to test whether your installation of Excel can close correctly when the Add-in is not loaded. In Visual Studio, from the Build menu choose "Clean Build". This will remove the Add-in from the Registry so that Excel will not load it.

    Now start Excel as an end-user (NOT debug mode). Do something in it similar to things you do when the add-in is running. (Obviously, you can't use those features.) Then close Excel the same way you do when running the add-in. Does Excel close without an error?


    Cindy Meister, VSTO/Word MVP
  • Tuesday, June 22, 2010 6:50 AM
     
     
    If I run in debug mode, there is no error while closing. When add-in is not loaded also, error is not coming. Once the add-in is loaded and some operation is performed, then the error comes. I am using thrid party dlls in my add-in.
  • Tuesday, June 22, 2010 6:54 AM
    Moderator
     
     Answered

    If it works in Debug mode, then you need to make sure that the version Excel is loading when NOT in debug mode is actually the updated version (the one where you removed those lines of code in ThisAddin_Shutdown).

    If that does not solve the problem, there's no way we can help you further, other than tell you how to go about trouble-shooting the problem. Obviously, it's something your add-in is doing, but there's no way to determine what that is for us, at this remove.

    My suggestion would be to first create a new add-in, with "skeleton code" - no real functionality. Check that this works properly.

    Then import the functionality of the problem add-in, bit-by-bit, in as small increments as possible. Test after each import until you isolate what's causing the problem.


    Cindy Meister, VSTO/Word MVP
  • Monday, March 26, 2012 4:24 PM
     
     
    I am utilizing this thread since I have a similar problem. Mine is Excel 2010. The file was originally created in 2007 version. I do not have any code to fire durnig close event in the macro but I still get this error message for all the Excel workbooks which have macro small or large. Please advise.
  • Tuesday, March 27, 2012 8:47 AM
     
     
    simply step by step comment out parts of your code and see where you stop getting crashes. Maybe you are holding somewhere references to office objects in partial state or som something in event handlers that corrupts internal state of excel. Are you using somewhere NativeWindow object or do som interop by yourself?