Sounds like you have problems in your code. If you fully qualify your
references to excel and clear those references, then excel should close
properly when a quit command issued.
http://support.microsoft.com/default.aspx?scid=kb;en-us;317109
Office application does not quit after automation from Visual Studio .NET
client
Tom,
Thanks for the prompt reply, but I think you misunderstood my question.
My cleanup function correctly clears all my excel references and calls the
Quit() function...so whenever the cleanup function gets called, everything is
fine. My problem is that when a user manually clicks the close button on an
excel window, I am not being able to detect that close event, and thus my
cleanup function does not even get called.
Does that make sense? Below is my cleanup function which works correctly.
private void cleanUpExcel()
{
if (excelApplication != null)
{
try
{
excelApplication.DisplayAlerts = false;
foreach (Excel.Workbook workbook in excelApplication.Workbooks)
{
foreach (Excel.Worksheet worksheet in workbook.Worksheets)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);
}
workbook.Close(false, Type.Missing, Type.Missing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApplication.Workbooks);
excelApplication.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApplication);
}
catch (Exception)
{
//Excel may have been closed via Windows Task Manager. Skip
the close.
}
}
}
Mehul.
> Sounds like you have problems in your code. If you fully qualify your
> references to excel and clear those references, then excel should close
[quoted text clipped - 19 lines]
> >
> > Thank you so much.
Tom Ogilvy - 20 Sep 2007 16:44 GMT
This group is primarily for internal VBA issues. Try asking over in the
below group:
http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public
.office.developer.automation&lang=en&cr=US

Signature
Regards,
Tom Ogilvy
> Tom,
>
[quoted text clipped - 65 lines]
> > >
> > > Thank you so much.