ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   0x800A03EC error during Application.WorkbookOpen event handler (https://www.excelbanter.com/excel-programming/424888-0x800a03ec-error-during-application-workbookopen-event-handler.html)

Andrew Wiles

0x800A03EC error during Application.WorkbookOpen event handler
 
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.Active Sheet as
Excel.Worksheet).Cells[query.StartRow, query.StartCol];
Excel.Range t2 = (Excel.Range)(Globals.ThisAddIn.Application.Active Sheet 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?



All times are GMT +1. The time now is 07:03 PM.

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