ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem Closing Excel (https://www.excelbanter.com/excel-programming/323917-re-problem-closing-excel.html)

m.ahrens

Problem Closing Excel
 
Found the solution...tried to close the objects in an excel event...how
should an object destroy it self from the inside...think i have to go to
school again;-)

have a nice day!

"m.ahrens" wrote:

Hi All

I have problems Closing excel...
Excel 2003 / Visual Studio 2003 / C#

The Code I use:

oExcel.WorkbookBeforeSave -= EventDel_BeforeBookSave;
oExcel.WorkbookDeactivate -= EventDel_Deactivate;

PIDHandler.NAR(wSheet);
wBook.Close(false, Type.Missing, Type.Missing);
PIDHandler.NAR(wBook);
PIDHandler.NAR(wBooks);
oExcel.Quit();
PIDHandler.NAR(oExcel);
GC.Collect();
GC.WaitForPendingFinalizers();

static public void NAR(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o);
}
catch
{
}
finally
{
o = null;
}
}

After Compleating the code above, Excel produces a total crash: "Microsoft
Office Excel has encountered a problem and needs to close. We are sorry for
the inconvenience." You know, this error, where you can send a "Error Report"
to microsoft. What might i be doing wrong?

thanks for your help

m.ahrens



All times are GMT +1. The time now is 11:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com