Excel Workbook.SheetDeactivated events disappearing

G

Gavin

Hi
I'm working on an excel add-in using the 2003 PIAs and VS C# .Net 2003

If I attach a Workbook.SheetDeactivate event it fails to get called
after the about the 40th call if I do this


private void SheetDeactivate(object _sheet)
{
try
{
Excel.Worksheet sheet = (Excel.Worksheet) _sheet;

for (int i = 0; i<50; i++)
{
Excel.Range cur_cell = (Excel.Range)sheet.Cells[1,1];
}

}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString(),"Addin");
}
}


further, if I try to reattach the event (using a button click event on
my custom button)

It gives an exception on detach and attach


Detaching the SheetDeactivate Event

System.NullReferenceException: Object reference not set to an instance
of an object.

at System.Runtime.InteropServices.UOCMIConnectionPoint.Unadvise(Int32
dwCookie)
at
Microsoft.Office.Interop.Excel.WorkbookEvents_EventProvider.remove_SheetDeactivate(WorkbookEvents_SheetDeactivateHandler)
at
Microsoft.Office.Interop.Excel.WorkbookClass.remove_SheetDeactivate(WorkbookEvents_SheetDeactivateHandler)
at Addin.Connect.Button_Click(CommandBarButton cmdBarButton, Boolean&
cancel)



Attaching the SheetDeactivate Event

at System.Runtime.InteropServices.UOCMIConnectionPoint.Advise(object
pUnkSink, Int32& dwCookie)
at
Microsoft.Office.Interop.Excel.WorkbookEvents_EventProvider.add_SheetDeactivate(WorkbookEvents_SheetDeactivateHandler)
at
Microsoft.Office.Interop.Excel.WorkbookClass.add_SheetDeactivate(WorkbookEvents_SheetDeactivateHandler)
at Addin.Connect.Button_Click(CommandBarButton cmdBarButton, Boolean&
cancel)






Any ideas what I could be doing wrong?

Thanks

Gavin
 
S

Steve Kirk (Insomniac Games)

Can someone at least tell me why I'm not getting a response to this?
I have an madn subscription isn't there supposed to be a response within 48
hours?

Steve Kirk (Insomniac Games) said:
Reposting using the msdn subscription account...

Gavin said:
Hi
I'm working on an excel add-in using the 2003 PIAs and VS C# .Net 2003

If I attach a Workbook.SheetDeactivate event it fails to get called
after the about the 40th call if I do this


private void SheetDeactivate(object _sheet)
{
try
{
Excel.Worksheet sheet = (Excel.Worksheet) _sheet;

for (int i = 0; i<50; i++)
{
Excel.Range cur_cell = (Excel.Range)sheet.Cells[1,1];
}

}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString(),"Addin");
}
}


further, if I try to reattach the event (using a button click event on
my custom button)

It gives an exception on detach and attach


Detaching the SheetDeactivate Event

System.NullReferenceException: Object reference not set to an instance
of an object.

at System.Runtime.InteropServices.UOCMIConnectionPoint.Unadvise(Int32
dwCookie)
at
Microsoft.Office.Interop.Excel.WorkbookEvents_EventProvider.remove_SheetDeactivate(WorkbookEvents_SheetDeactivateHandler)
at
Microsoft.Office.Interop.Excel.WorkbookClass.remove_SheetDeactivate(WorkbookEvents_SheetDeactivateHandler)
at Addin.Connect.Button_Click(CommandBarButton cmdBarButton, Boolean&
cancel)



Attaching the SheetDeactivate Event

at System.Runtime.InteropServices.UOCMIConnectionPoint.Advise(object
pUnkSink, Int32& dwCookie)
at
Microsoft.Office.Interop.Excel.WorkbookEvents_EventProvider.add_SheetDeactivate(WorkbookEvents_SheetDeactivateHandler)
at
Microsoft.Office.Interop.Excel.WorkbookClass.add_SheetDeactivate(WorkbookEvents_SheetDeactivateHandler)
at Addin.Connect.Button_Click(CommandBarButton cmdBarButton, Boolean&
cancel)






Any ideas what I could be doing wrong?

Thanks

Gavin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top