Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am getting "HRESULT: 0x800A03EC" error when running Excel add-in with following code:
C#
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: 
Posted
Updated 15-Oct-19 5:29am

I had to check if value was null, but it only worked in the certain way:
if (rng.Value2 != null){}
 
Share this answer
 
v2
It seems, that you are not the only one: http://stackoverflow.com/questions/7099770/hresult-0x800a03ec-on-worksheet-range[^].

According to the post, this error is occurring when you work with an old (xls) workbook opened in Excel 2007 or 2010. If this is the case, try first to save the file as new format workbook, before you access the cells.
 
Share this answer
 
About a year since this was asked but I got the same error and it was the most simple thing...
Solution 1 is the obvious: 0 based problem, but as you mentioned you already have 1 instead of 0.
Solution 2...when you are exporting to excel check that you don't have a symbol of equal (=) at the beginning of any data...Excel recognizes this as the beginning of a call or formula, so it tries to resolve something that maybe doesn't exist or can't be done.
Hope this helps to anyone who has this problem.
 
Share this answer
 
Comments
Niels Van Extergem 30-Nov-18 9:37am    
Thank you for your post, even after 5 years! We solved a production problem rather fast because of your post. Who would have tought!
alexcoder99 19-Jan-21 5:46am    
This also helped me to resolve a frustrating production issue due to writing unstructured data that unexpectedly contained an '=', so still relevant today! Very helpful, thanks.
Shebarn7625 18-Jun-21 6:01am    
Lo and behold!
Thanks, saved me a haedache :)
I had this same issue. My problem stemmed from my code. I had a really long code line, so I hit enter several places to break up the code and this caused my problem. It was trying to enter an invisible return carraige in my excel formula and would cause the program to crash. Removing my line breaks in the code fixed it.
Here is the long line I tried to break up. Works fine now.
newWorksheet.Cells[8, 7] = @"=TEXT(IF(ISNA(OFFSET(OFFSET(BGPM1000XX!M12,0,11*0),MATCH(BGPM1000XX!B5+0.001,BGPM1000XX!A12:OFFSET(BGPM1000XX!A12,7,0),-1),0)),OFFSET(OFFSET(BGPM1000XX!M12,0,11*0),MATCH(BGPM1000XX!$B$5-0.001,BGPM1000XX!A12:OFFSET(BGPM1000XX!A12,7,0),-1),0),OFFSET(OFFSET(BGPM1000XX!M12,0,11*0),MATCH(BGPM1000XX!$B$5+0.001,BGPM1000XX!A12:OFFSET(BGPM1000XX!A12,7,0),-1),0)),""$#,#00"")& "" - "" &TEXT(IF(ISNA(OFFSET(OFFSET(BGPM1000XX!O12,0,11*0),MATCH(BGPM1000XX!B5+0.001,BGPM1000XX!A12:OFFSET(BGPM1000XX!A12,7,0),-1),0)),OFFSET(OFFSET(BGPM1000XX!O12,0,11*0),MATCH(BGPM1000XX!$B$5-0.001,BGPM1000XX!A12:OFFSET(BGPM1000XX!A12,7,0),-1),0),OFFSET(OFFSET(BGPM1000XX!O12,0,11*0),MATCH(BGPM1000XX!$B$5+0.001,BGPM1000XX!A12:OFFSET(BGPM1000XX!A12,7,0),-1),0)),""$#,#00"")";
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900