How to fully terminate EXCEL.exe from running tasks in office.interop?

I have to open an excel file and want to get the data to word a document. I use to this code:

private Excel.Application excelapp;
Type ExcelType = Type.GetTypeFromProgID("Excel.Application");
dynamic ExcelInst = Activator.CreateInstance(ExcelType);
this.excelapp = ExcelInst;

this.workbook = this.excelapp.Workbooks.Open(Filename : this.filePath, ReadOnly: true);

I used all the techniques to close/quit/dispose the opened process (except for Process.Kill), but those won't work. How do I fully terminate any running background tasks?

You just need to call the Quit method of the Excel Application class when you are done:

private Excel.Application excelapp;
Type ExcelType = Type.GetTypeFromProgID("Excel.Application");
dynamic ExcelInst = Activator.CreateInstance(ExcelType);
this.excelapp = ExcelInst;

this.workbook = this.excelapp.Workbooks.Open(Filename : this.filePath, ReadOnly: true);

' do whatever you need there



If unsaved workbooks are open when you use this method, Excel displays a dialog box asking whether you want to save the changes. You can prevent this by saving all workbooks before using the Quit method or by setting the DisplayAlerts property to False. When this property is False, Excel doesn't display the dialog box when you quit with unsaved workbooks; it quits without saving them.

If you set the Saved property for a workbook to True without saving the workbook to the disk, Excel will quit without asking you to save the workbook. Note: this does not save the workbook; it just makes it look like it's saved.

Cannot close Excel.exe after Interop process, They might create the problem when you run the application next time. Basically, you need to close the workbook, quit the application, and then release Office.Interop.Excel; Application xls = null; Workbooks workBooks = null; Workbook The topic is simply too big to explore completely in an answer, but I think you'll� End Process to Winword.exe and Excel.exe in the task manager 3. Kill the process using taskkill.exe Although 1 is the easiest, it would also be time consuming to wait for the computer to start up again, launch all of the programs etc. #2 is fairly user-friendly as it allows you to click to select processes and end them but this too can be quite

My understanding is that since interop uses "COM" objects, you need to "release" those objects. Something like…


in that order. This should release those objects from the background tasks

I have had success with the following approach when using office-interop… Set up all the Excel/Word/Outlook. Etc.… interop stuff in a try/catch/finally statement. This should almost guarantee that your code will properly close and "release" the resources it uses even if there is an exception. Otherwise, the code will always be susceptible to leaking a resource.

Word.Application app = null;
Word.Document doc = null;
try {
  app = new Word.Application();
  //app.Visible = true;
  doc = app.Documents.Add();
  // do some stuff with the document…
  MessageBox.Show("Document created successfully !");
catch (Exception e) {
  MessageBox.Show("ERROR: " + e.Message);
finally {
  if (doc != null) {
  if (app != null) {

Can't kill Excel.Exe after using Excel component in, I've run loops, do until, etc. and nothing. this will kill only the associated excel. exe and not all the exe's in the task manager. I'm trying to pinpoint if there is some issue with Interop with Office 2003 which causes an issue. I may not be fully understanding the overall design of your app, but it seems to me as if you could� Xl = (Microsoft.Office.Interop.Excel.Application)new Microsoft.Office.Interop.Excel.ApplicationClass(); in both if block and else block. As far as I'm concernd, you are create a new instance of Excel.ApplicationClass() by using new, so there's an extra Excel.EXE process in the task manager always.

I use the following to open excel and read / update it.

Excel.Application app;
Excel.Workbook wb;
private void openAndRead()

 app = new Excel.Application();
 wb = app.Workbooks.Open(YourFileHere);

//do stuff here read or write
//app.ActiveSheet.Cells[1, "A"] = "write this in cell A1";
//string read= app.ActiveSheet.Cells[1, "A"]; 


private void closeExcel ()
 app.DisplayAlerts = false; //this will stop popup questions from excel

How to delete excel .exe from task manager, Capture the Process ID of the excel that you are running, then kill it when you Office.Interop.Excel object, you check for existing excel that are� Once I saved I am closing the Excel and quiting the Excel application by code and I am releasing the memory of the EXCEL as well. However, what ever I do, the instance of the EXCEL is still showing in the Task Manager until I completely close the whole application. This is my code

If you want to be confident that EXCEL.EXE process will go away, there's one way to realize it. May be this is not the elegant solution, but at least it does work. The main idea is to catch the Excel window's handle. Having this handle, you can get its process and shut it down.

WARNING: If you don't make Excel window visible, this method WILL NOT work!
using System.Diagnostics;
using Excel = Microsoft.Office.Interop.Excel;

void Kill_Excel()
    // Create instance of Excel application.
    // If you don't make Excel window visible, this method WILL NOT work!
    Excel.Application excel = new Excel.Application { Visible = true };
    // Catch Excel window handle
    IntPtr hwnd = new IntPtr(excel.Hwnd);
    // Get EXCEL.EXE process
    Process xlproc = Process.GetProcesses().Where(p => p.MainWindowHandle == hwnd).First();

    // Do some operations
    Excel.Workbook book = excel.Workbooks.Add();
    Excel.Worksheet sheet = book.Sheets[1] as Excel.Worksheet;
    sheet.Cells[1, 1] = "Hello!";

    // Close Excel
    book.Close(SaveChanges: false);

    // Garbage collection

    // Kill process - FOR SURE! :)

[Solved] Close Excel Process with Interop, Hey there, This is an issue I had for a long time aswell. I'm afraid that I did not find a solution by using the Interop. However I did create some� Im using C# 2010 and've added a reference to the Microsoft.Office.Interop.Excel. My Problem is : after calling the XLApp.close() method still leave the EXCEL.EXE Open in the Taskmanager

Killing EXCEL.exe Process from C# in a Windows Service, through and killing each Excel process is usually not a good idea, since if you' re running this EXE gets opened and (using Quit) closed at the end, leaving the first instance untouched. How do you think this answers contributes? Office. Interop.Excel.Application(); int nData = excelApp.Hwnd; // excelApp = new Excel. All server running on the ESXi 5.0. I test a lot of times, I kill all excel.exe professes before testing. I also restart the server for testing, but always one excel still running, the lastest process excel PID running, it means when I click to export excel, the excel process running on Task Manager but the previous excel process is killed auto.

How to properly release Excel COM objects: C# code examples, Net developers we can use the Office Interop Assemblies to access the various WaitForPendingFinalizersr; Ways to kill the Excel.exe process RCW for each COM object needs to run a finalizer that actually fully removes� Press F5 to run the application. Open Windows Task Manager. In Visual Studio, display the Output window to see the debug messages. Click the command button. Notice that an instance of Excel.exe appears in the Processes list. The instance of Excel still runs in the task list even after the application has finished sleeping.

50 Ways to Kill Excel, Web developers often ask about dozens of Excel.exe processes stacking up in For example, you may wish to kill all running instances of Excel, which is a Office.Interop.Excel.ApplicationClass Dim App As Microsoft.Office.

  • Show what you've tried that didn't work. People really do not want to make suggestions only to be told "I already tried that and it didn't work.", so it's necessary to list those things in the question - you can use the edit link to do so. Is there any reason you're not using this.excelapp = new Excel.Application();? And why is this tagged with ms-word when the question is not about Word?
  • "I used all the techniques to close/quit/dispose"
  • Where are they? :)
  • in your code you have the control over "app" you can keep track of it and use it wherever you see fit. if you then want to close the app you dont need to search for it in the process since you have full control.
  • But how is it different from what the OP has?
  • OP does not keep track of his open app and never closes/quits it
  • So many different approaches for closing the Excel process. The garbage collector should be called twice to make any effect.
  • @EugeneAstafiev I know, but sometimes it doesn't help either. The 100% method, however, is to kill process! 😆
  • DOWNVOTER, any explanations?
  • @EugeneAstafiev If you downvoted my answer, please, explain why?