Home » Visual StudioRSS

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

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();

 

 

 

5 Answers Found

 

Answer 1

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.

 

Answer 2

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

 

 

Answer 3

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?

 

Answer 4

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.
 

Answer 5

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.

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter