Exception from HRESULT: 0x800A03EC Error
Asked Answered
D

19

85

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: 
Dashtilut answered 3/10, 2012 at 18:31 Comment(3)
Did you get or find an answer to this problem?Throes
This error is very 'generic' and can be caused by many reasons. The reason it happened for me was saving a customer data type in C# to excel. I had this error when trying to save a date wrapper object; I guess excel api requires to data to be c# primitive type otherwise it can cause problem.Impenetrable
I am not sure how common this particular case is, so I am posting my resolution as a comment instead of an answer: I was using the wrong variable on the RHS in my range.value2 = <variable>' assignment. Type-checking in VS wasn't highlighting anything as incorrect, presumably because the range` is of type object (IE accepts any type?). Ended up being a simple fix for me, though aggravating upon realization.Sporogenesis
H
125

Got same error in this line

 Object temp = range.Cells[i][0].Value;

Solved with non-zero based index

 Object temp = range.Cells[i][1].Value;

How is it possible that the guys who created this library thought it was a good idea to use non-zero based indexing?

Heliocentric answered 16/1, 2013 at 17:54 Comment(3)
IMO, it might be related to the fact that Excel's cell-naming scheme is actually non-zero-based ("R1C1")...Lolita
BASIC indexes from 1. Excel included BASIC very early on (in the 1980's) as a macro/scripting language, which later led to Visual Basic for Applications. This was before the widespread use of C-like languages with their more mathematically correct zero-based indexing, which came into common use in the 1990's thanks to web technology including Java, Perl, and Javascript.Barehanded
Quite possibly, must have been developed with Basic developers in mind.Alfalfa
A
22

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

Affright answered 15/10, 2012 at 10:29 Comment(3)
It appears as though you may be correct on this. Unfortunately, I am still hitting the issue after one million and more records.Auxiliary
If the user is busy editing a formula, this error can persist indefinitely.Affright
This can also happen when the name is actually not found, e.g. malform or missing named range.Kindliness
V
8

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.

Velleman answered 15/10, 2012 at 10:12 Comment(0)
D
4

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.

edit ----

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:

http://support.microsoft.com/kb/320369

http://blogs.msdn.com/b/eric_carter/archive/2005/06/15/429515.aspx

Denticulate answered 3/10, 2012 at 18:36 Comment(3)
Thank you for the suggestion, but this is not the cause. I am working in Excel2010 and the exception did happen even after I saved as "xlsx". The weirdest part is it does not happen all the time, but only for certain combinations of data. I cannot find a pattern that causes it though.Dashtilut
can you please post your code for ThisAddin at link 354? Are you trying to trim the value in the cells? Also, are you sure that Cells[x,y] is not starting from 0? Cell values start from 1 and are not zero based in excel.Denticulate
I get this when a file name is too long (not sure what the limit is though)Mayapple
F
4

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.

Forked answered 8/7, 2014 at 15:31 Comment(0)
S
4

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

Sung answered 27/4, 2015 at 9:47 Comment(0)
C
3

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.

Clinquant answered 7/6, 2018 at 1:54 Comment(2)
I just spent an hour investigating this error in an SSIS package script. A field being exported to Excel was free-form entry, and it started with an = sign. A quick replace to strip all = signs out fixed it. Thank you!Jennette
So I'm guessing they're using office COM automation as underlying method to access Excel and it's functions as this happens to me only when I'm using COM. I have to say EPPlus or NPOI are easily much better ways to handle open xml format.Clinquant
E
2

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;
Edmundedmunda answered 4/7, 2014 at 7:8 Comment(0)
S
1

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

Starknaked answered 31/1, 2014 at 8:30 Comment(0)
P
1

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.

Puce answered 1/5, 2019 at 19:25 Comment(0)
G
0

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.

Gloriane answered 10/4, 2018 at 6:53 Comment(0)
H
0

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

Hannahannah answered 1/11, 2018 at 20:37 Comment(0)
P
0

I got this error when calling this code: wks.Range[startCell, endCell] where the startCell Range and endCell Range were pointing to different worksheet then the variable wks.

Packet answered 27/2, 2020 at 16:9 Comment(0)
P
0

An additional cause for this error. The code sample below returns the error when the datatable (dtTable) has a blank tablename:

  ' Open Excel workbook
  objExcelApp = New Application
  objExcelWorkbook = objExcelApp.Workbooks.Add()
  objExcelSheet = objExcelWorkbook.ActiveSheet
  objExcelSheet.Name = dtTable.TableName
Palaeozoology answered 20/10, 2020 at 13:20 Comment(0)
R
0

Still seeing this error in 2020. As was stated by stt106 above, there are many, many possible causes. In my case, it was during automated insertion of data into a worksheet, and a date had been incorrectly typed in as year 1019 instead of 2019. Since i was inserting using a data array, it was difficult to find the problem until I switched to row-by-row insertion.

This was my old code, which "hid" the problem data.

    Dim DataArray(MyDT.Rows.Count + 1, MyDT.Columns.Count + 1) As Object
    Try
        XL.Range(XL.Cells(2, 1), XL.Cells(MyDT.Rows.Count, MyDT.Columns.Count)).Value = DataArray
    Catch ex As Exception
        MsgBox("Fatal Error in F100 at 1270: " & ex.Message)
        End
    End Try

When inserting the same data by single rows at a time, it stopped with the same error but now it was easy to find the offending data.

I am adding this information so many years later, in case this helps someone else.

Riotous answered 12/11, 2020 at 20:54 Comment(0)
T
0

Issue that i have was on assigning the cell value..the value that i retrieved from DataTable columns has curly braces in it. the i need to ensure the data retrieved using .ToString() method.this exception is thrown to me when the value is not appropriate. hope this helps :D

Towroy answered 12/9, 2022 at 4:7 Comment(0)
P
0

For me it went away when we ran it (save excel workbook, using Excel = Microsoft.Office.Interop.Excel) on the server with a system account. We had load profile settings checked. I think it has to do with write access to the dir's on the server. Or it could be because we are accessing a different file share.

Penguin answered 17/10, 2022 at 16:48 Comment(0)
T
0

This is a generic error, but another thing to look for is C# Guid? types when assigning an object array to .Value2 of an excel range. Interop doesn't like this C# type for some reason. Try coercing the Guid? type object to a string.

Trevino answered 17/5, 2023 at 16:44 Comment(0)
L
-1

I was getting the same error but it's sorted now. In my case, I had columns with the heading "Key1", "Key2", and "Key3". I have changed the column names to something else and it's sorted.

It seems that these are reserved keywords.

Regards, Mahesh

Ligetti answered 10/12, 2020 at 16:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.