Click here to Skip to main content
16,020,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try do open, edit, and save a word document and an excel workbook in my program.
I write some code like below.
After the program exit,
I find the WORD.EXE in TaskManager is quit, but the EXCEL.EXE is still running.
Why does the oExcel.quit() not work??
Please give me some advice, thanks!!
                Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
                
                object fileName = @"D:\Combo.docx";
                Document oDoc = oWord.Application.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
...                
                oDoc.Close(ref saveChange, ref oMissing, ref oMissing);
                oDoc = null;
                oWord.Quit(ref saveChange, ref oMissing, ref oMissing);
                oWord = null;
...
                Microsoft.Office.Interop.Excel.Application oExcel = new Microsoft.Office.Interop.Excel.Application();
                String fileName3 = @"D:\Combo.xlsx";
                Workbook excelWorkbook = oExcel.Workbooks.Open(fileName3,
                    0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "",
                    true, false, 0, true, false, false);
...
                excelWorkbook.Close(saveChange, oMissing, oMissing);
                excelWorkbook = null;
                oExcel.Quit();
                oExcel = null;
Posted

I'v had the same problem before.

Didn't find a waterproof solution but did find something that works 99% of the time.

After you call the quit methode release the object and run the garbagecollector
oExcel.quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel);
GC.collect();



No guarantees tho
 
Share this answer
 
v2
Why does it matter ? You've obviously abandoned your connection to it.
 
Share this answer
 
Because I don't know how to check if the EXCEL is running.
If I run my program 10 times, there will be 10 EXCEL.EXE in the TaskManager.
Besides, my program will run on a server later, I don't want it to keep an EXCEL.exe to hold the system resource.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900