I’m trying to find all the open excel workbooks and kill one particular one.
But when i loop through and print the title of the workbook , It just display only one ,though i have opened multiple workbooks.
//Excel Application Object
Microsoft.Office.Interop.Excel.Application oExcelApp;
this.Activate();
System.Diagnostics.Process[] AllProcesses = System.Diagnostics.Process.GetProcessesByName("excel");
foreach (Process ExcelProcess in AllProcesses)
{
//Display the name of the object.
MessageBox.Show(oExcelApp.ActiveWorkbook.FullName);
//if (myHashtable.ContainsKey(ExcelProcess.Id) == false)
// ExcelProcess.Kill();
}
This works for me: