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
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