Exception from HRESULT: 0x800A03EC Error
I am getting "HRESULT: 0x800A03EC" error when running Excel add-in with following code:
Excel.Range rng = ActiveSheet.Cells[x, y] as Excel.Range; string before = rng.Value2; string cleanV = System.Text.RegularExpressions.Regex.Replace(before, @"\s+", ""); rng.set_Value(cleanV);
When error happens X and Y are set to 1, thus Excel range is not violated. I searched extensively and tried a number of ways of setting the cell value (eg. Cells[x,y], range.set_Value()) but am at loss why this error happens and how to avoid it.
Any help is greatly appreciated.
Below are exception details:
System.Runtime.InteropServices.COMException was unhandled by user code HResult=-2146827284 Message=Exception from HRESULT: 0x800A03EC Source="" ErrorCode=-2146827284 StackTrace: at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32 aWrapperTypes, MessageData& msgData) at Microsoft.Office.Interop.Excel.Range.set_Value(Object RangeValueDataType, Object value) at ImportValidation.ThisAddIn.removeAnySpaces(Int32 x, Int32 y) in c:\Users\dshevelev\Documents\Visual Studio 2012\Projects\ImportValidation\ImportValidation\ThisAddIn.cs:line 354 at ImportValidation.ThisAddIn.ReadHeaders(Hashtable columnAddress) in c:\Users\dshevelev\Documents\Visual Studio 2012\Projects\ImportValidation\ImportValidation\ThisAddIn.cs:line 123 at ImportValidation.ThisAddIn.mapColumns() in c:\Users\dshevelev\Documents\Visual Studio 2012\Projects\ImportValidation\ImportValidation\ThisAddIn.cs:line 493 at ImportValidation.Ribbon1.button6_Click(Object sender, RibbonControlEventArgs e) in c:\Users\dshevelev\Documents\Visual Studio 2012\Projects\ImportValidation\ImportValidation\Ribbon1.cs:line 55 at Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ControlActionRaise(IRibbonControl control) at Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ButtonClickCallback(RibbonComponentImpl component, Object args) at Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.Invoke(RibbonComponentCallback callback, Object args) at Microsoft.Office.Tools.Ribbon.RibbonMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture) at Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.System.Reflection.IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object args, ParameterModifier modifiers, CultureInfo culture, String namedParameters) InnerException:
Got same error in this line
Object temp = range.Cells[i].Value;
Solved with non-zero based index
Object temp = range.Cells[i].Value;
How is it possible that the guys who created this library thought it was a good idea to use non-zero based indexing?
This is a common but poorly documented Excel COM Error. I've seen it documented as "NAME_NOT_FOUND", meaning that Excel's COM layer is disabled, and can't find the COM property or method name.
I get this error consistently when running the COM code while Excel is 'busy', for example if you set a timer that will start the code, and the code starts running while the user is editing a cell or pressing down their mouse button, then you'll always get this error. This error only happens when the code runs on the main Excel thread, but seems to be the equivalent of error VBA_E_IGNORE = 0x800AC472, which you get when calling the Excel COM object model from another thread, while Excel is 'busy'.
The only workaround seems to be to retry (with some small delay) the COM call until it succeeds - when Excel is no longer 'busy'.
Check your start indexes. Its start from 1 not 0 for Microsoft.Office.Interop.Excel range objects. I had received same error because of my loop start value.
We had the same problem and found for us the solution :
Please make this folder. C:\Windows\SysWOW64\config\systemprofile\Desktop ·Windows 2008 Server x86 Please make this folder. C:\Windows\System32\config\systemprofile\Desktop
Go to Excel Options > Save > Save Files in this format > Select "Excel Workbook(*.xlsx)". This problem occurs if you are using an older version of excel file (.xls) instead of .xlsx. The older version does not allow more than 65k rows in the excel sheet.
Once you have saved as .xslx, try executing your code again.
Looking more into your problem, it seems that the problem might be locale specific. Does the code work on another machine? What value does the cell have? Is it datetime format? Have a look here:
Got this error also....
it occurs when save to filepath contains invalid characters, in my case:
path = "C:/somefolder/anotherfolder\file.xls";
Note the existence of both \ and /
*Also may occur if trying to save to directory which doesn't already exist.
Got the same error when tried to export a large Excel file (~150.000 rows) Fixed with the following code
Application xlApp = new Application(); xlApp.DefaultSaveFormat = XlFileFormat.xlOpenXMLWorkbook;
I know this is old but just to pitch in my experience. I just ran into it this morning. Turns our my error has nothing to do with .xls line limit or array index. It is caused by an incorrect formula.
I was exporting from database to Excel a sheet about my customers. Someone fill in the customer name as =90Erickson-King and apparently this is fine as a string-type field in the database, however will result in an error as a formula in Excel. Instead of showing #N/A like when you're using Excel, the program just froze and spilt that 0x800A03EC error a while later.
I corrected this by deleting the equal sign and the dash in the customer's name. After that exporting went well.
I guess this error code is a bit too general as people are seen reporting quite a range of different possible causes.
I got the same error whilst using Excel 2003 DLLs and trying to write to the 257th column. Excel 2003 limits maximum column per worksheet to 256, thus raising this exception.
For detailed limitations of Excel 2003, see http://office.microsoft.com/en-001/excel-help/excel-specifications-and-limits-HP005199291.aspx
Starting from Excel 2007, column limitation is increased to 16384 columns, see http://office.microsoft.com/en-001/excel-help/excel-specifications-and-limits-HP010073849.aspx
I was receiving the same error some time back. The issue was that my XLS file contained more than 65531 records(500 thousand to be precise). I was attempting to read a range of cells.
Excel.Range rng = (Excel.Range) myExcelWorkbookObj.UsedRange.Rows[i];
The exception was thrown while trying to read the range of cells when my counter, i.e. 'i', exceeded this limit of 65531 records.
Adding one more possible issue causing this: the formula was wrong because I was using the wrong list separator according to my locale. Using CultureInfo.CurrentCulture.TextInfo.ListSeparator; corrected the issue.
Note that the exception was thrown on the following line of code...
This must be the world's most generic error message because I got it today on the following command using Excel Interop:
Excel.WorkbookConnection conn; conn.ODBCConnection.Connection = "DSN=myserver;";
What fixed it was specifying ODBC in the connection string:
conn.ODBCConnection.Connection = "ODBC;DSN=myserver;";
On the off chance anyone else has this error, I hope it helps.