0x800A03EC error during Application.WorkbookOpen event handler

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?
 

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