Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Excel Exception Interop Errors , +
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: 
Posted 3-Oct-12 9:34am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I had to check if value was null, but it only worked in the certain way:
 if (rng.Value2 != null){}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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"")";
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 152
2 ProgramFOX 130
3 Maciej Los 130
4 den2k88 80
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 21 Jan 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100