A
Andrew Wiles
I am building a VSTO C# add-in for Excel (Office 2003 and Office 2007)
I have an event handler for the Application.WorkbookOpen which refreshes
data in a workbook. Prior to refreshing the data I need to clear old data and
formatting. The code for this is:
Excel.Range t1 = (Excel.Range)(Globals.ThisAddIn.Application.ActiveSheet as
Excel.Worksheet).Cells[query.StartRow, query.StartCol];
Excel.Range t2 = (Excel.Range)(Globals.ThisAddIn.Application.ActiveSheet as
Excel.Worksheet).Cells[query.EndRow, query.EndCol];
Excel.Range range1 = Globals.ThisAddIn.Application.get_Range(t1, t2);
range1.ClearFormats();
range1.Clear();
The ClearFormats (or Clear if it is placed first) will generate an
0x800A03EC exception. Unfortunately the error message is not very helpful as
it gives no indication as to why the call failed.
The same code when called after the workbook has fully opened is working
fine. Application.Ready is true at the point that the clear functions are
called.
Any ideas as to what might be going on?
I have an event handler for the Application.WorkbookOpen which refreshes
data in a workbook. Prior to refreshing the data I need to clear old data and
formatting. The code for this is:
Excel.Range t1 = (Excel.Range)(Globals.ThisAddIn.Application.ActiveSheet as
Excel.Worksheet).Cells[query.StartRow, query.StartCol];
Excel.Range t2 = (Excel.Range)(Globals.ThisAddIn.Application.ActiveSheet as
Excel.Worksheet).Cells[query.EndRow, query.EndCol];
Excel.Range range1 = Globals.ThisAddIn.Application.get_Range(t1, t2);
range1.ClearFormats();
range1.Clear();
The ClearFormats (or Clear if it is placed first) will generate an
0x800A03EC exception. Unfortunately the error message is not very helpful as
it gives no indication as to why the call failed.
The same code when called after the workbook has fully opened is working
fine. Application.Ready is true at the point that the clear functions are
called.
Any ideas as to what might be going on?