Why does calling Quit() on an Interop.Excel.Application in a .Net application not terminate the process?

Posted on 2013-10-28
Last Modified: 2013-10-28

I'm having issues using Microsoft Interop.Excel.Application in my .Net program.

Consider the following code snippet:
                // Open to force Excel to perform calculation itself
                Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
                //excelApp.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlMinimized;
                var excelWorkbook = excelApp.Workbooks.Open(tempFileName);
                excelApp = null;

Open in new window

When I check in Task Manager, I notice that the EXCEL.EXE task created by the above code snippet does not terminate.

I'm not directly accessing any of the worksheets.
For my purposes all I need to do is:
1) Launch the application (which will force a recalc on open)
2) Save the spreadsheet
3) Terminate the application

What am I missing here?
Is there some sort of COM object that needs to be released?

Question by:jxbma
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 39606863
Did you try closing the workbook after saving it so that there are no open workbooks when invoking the Quit method?


Expert Comment

ID: 39606927
You may need to kill the excel process.

Process[] AllProcesses = Process.GetProcessesByName("excel");
// check to kill the right process
  foreach ( Process ExcelProcess in AllProcesses)
    if (myHashtable.ContainsKey(ExcelProcess.Id) == false)
AllProcesses = null;

Ref Link:

Hope this helps.
LVL 21

Accepted Solution

Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 500 total points
ID: 39606998
It sounds like you code may be starting two instances of Excel and only closing one.

You may also want to check out this:
How to open an Excel file in C#

Author Closing Comment

ID: 39607078
There are not 2 instances of Excel running.

I just need to do a release on the workbook and application COM objects.
Thanks for pointing me in the right direction.


Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

739 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