Home » Visual Studio

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


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 = null;





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.




The following error is causing me grief, if anyone has any ideas, that would be great.

Microsoft has encountered an error and needs to close.

The error is intermitent. i have only been able to catch it once, and it fell over in the subprocedure.

I have done the following.

1. compact repair

2. Transfer all tables etc to new db, Turned off spell check, decompiled - compiled.


I have created a search form, when your choose a record it applies the record to another form.

This is Access 2003 running on a server with a frontend - backend.

I can not find any corrupt data - not to say there is not any.

I wonder if the code i have written is causing the problem, or maybe the network drops out for a split second when the code runs causing the error.

Here is the logic behind the form.
This is a disease tracking system.

Open frmNotificationCore - click button Open Search Disease.

frmSearchResident - and fsubSearchResident opens ontop of frmNotificationCore.

click on a record - then click button Choose Record.

    Forms!frmNotificationCore.SetRecord Me!fsubSearchResident!NotificationDetailsOid

Following code is sitting in frmNotificationCore.

Public Sub SetRecord(NotificationDetailsOid As Long)
' Find based on oid
Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[NotificationDetailsOid] = " & NotificationDetailsOid
    If Not rs.EOF Then
        Me.Bookmark = rs.Bookmark
        ' close the calling form
    End If



Written a unit test methods for a component which has a static constructor, which gets the configuration values from config file and assign to static variables.  It is referring to c:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\Microsoft.Moles.VsHost.x86.exe.config file.

Placed all the appsetting config values in Microsoft.Moles.VsHost.x86.exe.config file. When trying to run unit test methods getting error message box with below message.

"Microsoft.Moles.VsHost has encountered a problem and needs to close.  We are sorry for the inconvenience."


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 = null;





We have created a project that compiles, links, and executes just fine.  However, when I build, Microsoft.Office.Interop.Excel.dll and office.dll appear in my bin directory.  There are no references to either of these in our application, and if I delete them from my bin directory the application runs just fine.

I have Visual Studio 2008 and Office 2003 on my PC.

When my colleague builds, these two libraries do not appear in the bin directory.

He has Visual Studio 2008 and Office 2007 on his PC.

Can someone help me figure out what is causing my PC to include these unnecessary DLLs?



I need to open Excel 2007 files with over 2700 columns each. I tried using OLEDB and it only retrieves the first 255 columns on each query. Cannot seem to get them all at once. Then I tried Office Interop. I am able to transform the Used Range into a DataTable. Now the problem is that I cannot migrate my code and compile it if the target machine does not have Office Installed.

Is there a way I can install the Interop assamblies without installing Office?
Efrain Juarez



We are using MS Project 2007 Professional not server. We also have service pack 2 installed as well as 1 patch beyond that.

We at our whole organizational area are getting this error dialog coming up in MS Project. There is no one thing we can pinpoint to what is causing this.

It will all of a sudden come up in the middle of updates we are applying but it could be any kind-of of an update.

The error message dialog box is "Microsoft Office Project has encountered a problam and needs to close. We are sorry for the inconvenience. If you were in the middle of something, the information you were working on might be lost. Please tell Microsoft aboyut this problem. Send error report. Don't send.


All users (50) from multiple sites printing to TS 2008 receive this error "Windows Presentation Foundation Terminal Server Print W has encountered a problem and needs to close.  We are sorry for the inconvenience."  The docments print from terminal server, just the error shows every time you print.

All systems are Windows XP Pro SP3, microsoft framework .net 3.0 sp1, rdp 6.1

All systems were printing without the error until mid October.  The event log shows no sign of this error.  Windows presentation foundation service is started, all updates on the terminal server are installed.

Any suggestions will be appreciated.
Hi thiere,
Once I log in I get this message, can anyone help?

Windows Live Messenger has encountered a problem and needs to close

Error Signature:

AppName: msnmsgr.exe      AppVer: 14.0.8089.726     AppStamp:4a6ce533 ModName: mshtml.dll      ModVer: 8.0.6001.18854      ModStamp:4ae94820 fDebug: 0       Offset: 00209f9c

Thank you for your time!


Hi Guys,

I am having a very strange problem. I have created an application on Visual Studio 2008 SP1 and if from VS I run the application as Debug or Release version the application runs perfectly. The problem happens when I go to the directory ...\MyApplication\Release\MyApplication.exe and double click the exe file, a error message comes up with: MyApplication.exe has encountered a problem and needs to close. We are sorry for the inconvenience.

I have no idea how to solve it. If I do the same process with other application everything goes well.


I have a TCP server which sends/receives data asynchronously. Occasionally I get the exception "the connection was forcibly closed by the remote host" which is expected as networking is not perfect.

This is fine for my receiving code, but occasionally my begin send code throws this exception which then leads to the error "<ProgramName> has encountered a problem and needs to close" popping up outside of the application (the windows error). The server application continues to work fine, sending and receiving data with no issue at all while this is happening (until of course I hit the close button on the error).

The software is to be used professionally and as such this error, even though seemingly harmless but annoying, can't be tolerated. Does anyone have any idea why this error is appearing (when it doesn't during the receive code which has the same exception handling and the same checks before doing the send/receive)?

My code:

publicvoid Send(String ToSend, int AddNull)
        if (!Disconnected && ClientCallback != null && ClientSocket != null && ClientSocket.Connected)
          if (Settings.LogLevel >= 2)
            Output.Write("Client" + ClientID, false, "Sending packet");

          // Add null bytes on if neededfor (int i = 0; i < AddNull; i++)
            ToSend += "\x00";

          // Convert to bytes
          Byte[] ToSendByte = Settings.Encoder.GetBytes(ToSend);

          // Send the bytes
          ClientSocket.BeginSend(ToSendByte, 0, ToSendByte.Length, SocketFlags.None, new AsyncCallback(SendFinish), null);
      catch (SocketException e)
        if (e.ErrorCode != 10054)
          Output.Write("Client " + ClientID, true, "Socket exception code " + e.ErrorCode);

        if (Settings.LogLevel >= 1)


The exception block is the same as in the receive function and I've tried commenting the SocketDisconnect method out so I know it's not that. Likewise with the checks (I.E. if ClientSocket != null etc...). Both get the exception (with receive being far more common presumably due to the socket rarely closing forcefully directly before a send) but only this causes the error. The logged exception is below:

Exception thrown on 9/26/2010 12:59:59 PM: System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
  at System.Net.Sockets.Socket.BeginSend(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state)
  at AnonMTS.Server.ClientConnection.Send(String ToSend, Int32 AddNull)
Any ideas? Any help is appreciated.


I have a new computer running Windows 7 Ultimate 64-bit and the only software that I have installed so far is Visual Studio 2008 and 2010.  2008 works fine, but I can't do anything in 2010 without resulting in a crash - it's completely unstable.

Windows 7 is up to date and I originally installed Visual Studio 2010 Service Pack 1 but this did not help.   I attempted to 'repair' both the service pack and the 2010 installation and this did not help either. 

Next, I completely uninstalled both the service pack and Visual Studio 2010 and then re-installed Visual Studio.  It still crashes on just about any action I try to take.

I have seen dozens of reports of this same issue and have tried many of the suggested fixes but without success.




I have an application I am supporting for a developer that has left the company. When the users are not interacting with the application, it encounters a system error and needs to close. It gives me the library that it happened in. I have asked around and it seems the consensus is that it is a timer. All of the timers are wrapped in a try/catch block. The code and different elements in the project amount to a lot of lines of code, over 10,000. I have ran the application on a pc, however it isn't running into the error for me. Their machines it happens about once a day. I am looking for any ideas or any help/direction that can be provided. 


My server is windows 2008 R2. Everything is running well except the following.

Whenever I tried to export to excel using:

Microsoft.Office.Interop.Excel.ApplicationClass app = new Microsoft.Office.Interop.Excel.ApplicationClass();

It shows exception:

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005

I searched on google, almost every suggestion told me to find Microsoft Excel Application in DomConfig. But I found no Microsoft Excel in DomConfig. Please note, I have Excel 2003 & 2007 on that server.

Please help me, its really urgent.


Hi ,

I need to create some Excel Report using C#. I don't have excel installed in Server. So i need to use Microsoft.Office.Interop.Excel Reference.

Can I get sample code for creating Excel file.




I need to create an excel file from the database records. I fetched and put the data in an excel file and tried to save that file as follows.


string SavedFileName = Server.MapPath("../NLR/WIP/WIP_" + toDay + ".xls");

excelWorkbook.SaveAs(SavedFileName, Excel.

XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing);


//@@ and released the excell process withthe following function



void killExcelProc()


foreach (System.Diagnostics.Process Proc in System.Diagnostics.Process.GetProcessesByName("EXCEL"))





** Now in my XP machine IIS server it is running fine with out any problem. But in windows 2003 Server I am getting the following error
System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Office Excel cannot access the file 'D:\RadioSQA\NLR\WIP'. There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook. at Excel.WorkbookClass.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object TextVisualLayout) at Reports_WIP.btnWIP_Click(Object sender, EventArgs e)

When I opened task manager I didn't find any excel process running. I have given the full permission to the virtual directory (Deployed folder) for ASPNET user. I modified the DCOMConfig configeration (For XP it is ASPNET and for 2003 it is NETWORK SERVICE). I think my application is not being able to save the excel file in the application. But I don't know why.. Please give me light and also tell me what I will have to do.


hi all. when i'm using Range.Group method from Interop.Excel it groups me by columns, the issue is that i want to group my data by rows .

this is my code:

static object useDefault = Type.Missing;

static void SetCellValue(Worksheet targetSheet, string cell,
            object value)
            targetSheet.get_Range(cell, useDefault).set_Value(
                XlRangeValueDataType.xlRangeValueDefault, value);

static void GenerateGroupedRows()
            // Declare variables that hold references to excel objects.
            ApplicationClass excelApplication = null;
            Workbook excelWorkBook = null;
            Worksheet targetSheet = null;
            Range testRange = null;

            // Declare helper variables.
            string workBookName = @"E:\TestExcel.xlsx";
            string workSheetName = "group rows";
                // Create an instance of Excel.
                excelApplication = new ApplicationClass();

                //Create a workbook and add a worksheet.
                excelWorkBook = excelApplication.Workbooks.Add(

                targetSheet = (Worksheet)(excelWorkBook.Worksheets[1]);
                excelWorkBook.Worksheets.Add(System.Reflection.Missing.Value, targetSheet, 1, System.Reflection.Missing.Value);
                targetSheet.Name = workSheetName;

                // Add Data to the Worksheet.

                SetCellValue(targetSheet, "A2", "0");
                SetCellValue(targetSheet, "B2", "1610");
                SetCellValue(targetSheet, "C2", "0");
                SetCellValue(targetSheet, "D2", "0");
                SetCellValue(targetSheet, "E2", "0");
                SetCellValue(targetSheet, "F2", "1000");
                SetCellValue(targetSheet, "G2", "0");
                SetCellValue(targetSheet, "H2", "1000");

                SetCellValue(targetSheet, "A3", "1610");
                SetCellValue(targetSheet, "B3", "1610.01");
                SetCellValue(targetSheet, "C3", "0");
                SetCellValue(targetSheet, "D3", "0");
                SetCellValue(targetSheet, "E3", "0");
                SetCellValue(targetSheet, "F3", "500");
                SetCellValue(targetSheet, "G3", "0");
                SetCellValue(targetSheet, "H3", "500");

                SetCellValue(targetSheet, "A4", "1610.01");
                SetCellValue(targetSheet, "B4", "1610.01.01");
                SetCellValue(targetSheet, "C4", "0");
                SetCellValue(targetSheet, "D4", "0");
                SetCellValue(targetSheet, "E4", "0");
                SetCellValue(targetSheet, "F4", "250");
                SetCellValue(targetSheet, "G4", "0");
                SetCellValue(targetSheet, "H4", "250");

               testRange = targetSheet.get_Range("A2", "H4");


               testRange .Group(useDefault, useDefault, useDefault, useDefault);

                // Save the Workbook.
                excelWorkBook.SaveAs(workBookName, useDefault, useDefault,
                    useDefault, useDefault, useDefault,
                    XlSaveAsAccessMode.xlNoChange, useDefault, useDefault,
                    useDefault, useDefault, useDefault);

            catch (Exception ex)
                // Release the references to the Excel objects.
                testRange = null;

                // Release the Workbook object.
                if (excelWorkBook != null)
                    excelWorkBook = null;

                // Release the ApplicationClass object.
                if (excelApplication != null)
                    excelApplication = null;




When opening Outlook, I'm getting the message "Microsoft CRM Web Service Hoster has encountered a problem". I have tried to reinstall the outlook client, it did not help. I'm using CRM 4.0. What could be solution for this?

Error signature:

EventType : clr20r3     P1 : microsoft.crm.application.hoster     P2 :
P3 : 475914c0     P4 : system     P5 :     P6 : 4ba85929     P7 : 38d0
P8 : 131     P9 : system.componentmodel.win32



Installed SharePoint 2010 Workspace on two machines: one works perfectly; the other crashes After the start-up splash screen and the one-inch square message "Creating an account", I am taken to the option of creating an account or restore an existing account Two or three seconds later, regardless what option I pick, or choose to do nothing, the configuration wizard crashes, with "Microsoft Sharepoint Workspace has encountered problem." Have uninstalled and re-installed SharePoint Workspace Have uninstalled and re-installed all of Office 2010 Have tried installing SharePoint only as "Run on first use" Have run command.com, gone to groove and run groove.exe/clean/all Operating system: Windows XP SP 3, running as admin All other Office 2010 features run smooth as silk

Just deployed Office Web Apps to our SharePoint 2010 environment. This environment was upgraded from a fresh deployment of SharePoint 2007 SP2. Configured all of the Application Services per http://technet.microsoft.com/en-us/library/ff431687.aspx, but I cannot open an Excel workbook, receiving the error: "This workbook cannot be opened because it is not stored in an Excel Services Application trusted location. To create an Excel Services Application trusted location, contact your system administrator."

Our farm has a single front end server and a single database server. The shared application pool is called SSP1_v14 (renamed during the upgrade from SSP1?). Our existing site had its visual style upgraded during the conversion. An in-place upgrade had been performed.

I went to Central Administration > Excel Services Application > Trusted File Locations and the default entry for address http://, Location Type: Microsoft SharePoint Foundation, Trust Children had already been created. Various blog posts on the internet indicate that this entry is all that's needed to setup a trusted location for all SharePoint sites, but it's not working here. I've tested Word document viewing with the Word Web App and that works fine.

Any ideas?


I am looking for help on deploying a visual studio solution, which has used Microsoft Office as one of the helper library component, on my non-office server.

I am building a small utility that is using “Microsoft.Office.Interop.Excel”.  The utility compiled and ran fine on my development machine, as long as I tried to run it from one of our test server; it complained that Microsoft.Office.Interop.Excel is missing.  I went out and research, I ended up with something call Microsoft Office 2007 redistributed package (PIA).  I tried to download this installation o2007pia.msi package and install it on the server; the installation went very quick without any indication whether the process had failed or succeeded.  I tried to run the utility again, the same error reported.  This gets my frustration level beyond anything anyone could imagine.

I do not understand what may’ve caused the issue and what would be a proper way to deploy Microsoft.Office.Interop.Excel along with my utility.  If there is a way to verify to see whether o2007pia.msi had indeed installed properly on my non-office server, it would be extremely helpful.


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure