27

I am working with Window Service project. that have to write data to a sheet in Excel file in a sequence times.

But sometimes, just sometimes, the service throw out the exception "Exception from HRESULT: 0x800A03EC" while it's trying to get range with cell's name.

I have put the code of opening excel sheet, and getting cell here.

  • OS: window server 2003 Office:
  • Microsoft Office 2003 sp2

1: Opening excel sheet

m_WorkBook = m_WorkBooks.Open(this.FilePath, 0, false, 5,
     "", "", true, Excels.XlPlatform.xlWindows, ";",
     true, false, 0, true, 0, 0);

2: Getting cell to write

protected object m_MissingValue = System.Reflection.Missing.Value;
Range range = m_WorkSheet.get_Range(cell.CellName, m_MissingValue);
// error from this method, and cell name is string.
jdehaan
  • 19,700
  • 6
  • 57
  • 97
Teerasej
  • 1,486
  • 4
  • 21
  • 31
  • the way you say "just sometimes" makes me think of the answer to this : http://stackoverflow.com/questions/20422387/adding-formula-to-cell-exception-from-hresult-0x800a03ec/26591841#26591841 – hello_earth Oct 27 '14 at 16:11
  • 2
    I have the same problem In C# code I typed `xApp.Cells(3, 1).FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"` : fails; then `xApp.Cells(3, 1).FormulaR1C1 = "=(R[-2]C+R[-1]C)"` : fails; and then `xApp.Cells(3, 1).FormulaR1C1 = "=A1+A2"` success – Fabrice T Jul 12 '16 at 10:52

15 Answers15

29

The error code 0x800A03EC (or -2146827284) means NAME_NOT_FOUND; in other words, you've asked for something, and Excel can't find it.

This is a generic code, which can apply to lots of things it can't find e.g. using properties which aren't valid at that time like PivotItem.SourceNameStandard throws this when a PivotItem doesn't have a filter applied. Worksheets["BLAHBLAH"] throws this, when the sheet doesn't exist etc. In general, you are asking for something with a specific name and it doesn't exist. As for why, that will taking some digging on your part.

Check your sheet definitely does have the Range you are asking for, or that the .CellName is definitely giving back the name of the range you are asking for.

Dominic Zukiewicz
  • 8,258
  • 8
  • 43
  • 61
  • 3
    can you provide a reference to corroborate your statement that "The error code 0x800A03EC (or -2146827284) means NAME_NOT_FOUND"? I haven't been able to find one... – ForeverWintr Apr 05 '13 at 17:48
  • @ForeverWintr: I'm trying to dig up a link, but this reply was from 10 months ago and based on my research at the time. I have also been building Excel based VSTO solution for a while and have seen this quite a lot when it cannot locate an item by name, by range etc. Its a very generic error, so it can come up in other Office applications and mean something different (like file saves, automation errors), but if it doesn't work for this OP, its helped me resolve similar issues in the past. – Dominic Zukiewicz Apr 07 '13 at 11:18
  • The reason I ask is that I've been encountering 0x800A03EC with such frequency and from such a diverse range of calls in my VSTO project that I'm beginning to think it just means "Excel error." Your answer is the only reference to "NAME_NOT_FOUND" that I've come across. – ForeverWintr Apr 08 '13 at 16:25
  • 2
    @ForeverWintr you use the Err.exe tool, its a command line tool, simply put it in System32 and call it from a dos prompt: `err 0x800A03EC`, it uses OS Header File's. – Jeremy Thompson Aug 16 '13 at 06:00
6

I ran into this error because I was attempting to write a string to a cell which started with an "=".

The solution was to put an "'" (apostrophe) before the equals sign, which is a way to tell excel that you're not, in fact, trying to write a formula, and just want to print the equals sign.

ebrts
  • 361
  • 2
  • 7
  • 17
4

I got the error with a space in a Sheet Name:

using (var range = _excelApp.Range["Sheet Name Had Space!$A$1"].WithComCleanup())

I fixed it by putting single quotes around Sheet Names with spaces:

using (var range = _excelApp.Range["'Sheet Name Had Space'!$A$1"].WithComCleanup())
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
4

I found a possible solution here: http://www.made4dotnet.com/Default.aspx?tabid=141&aid=15

Edit:

If you automate Microsoft Excel with Microsoft Visual Basic .NET, Microsoft Visual C# .NET, or Microsoft Visual C++, you may receive the following errors when calling certain methods because the machine has the locale set to something other than US English (locale ID or LCID 1033):

Exception from HRESULT: 0x800A03EC

and/or

Old format or invalid type library

SOLUTION 1:


To get around this error you can set CurrentCulture to en-US when executing code related to Excel and reset back to your originale by using these 2 functions.

//declare a variable to hold the CurrentCulture
System.Globalization.CultureInfo oldCI;
//get the old CurrenCulture and set the new, en-US
void SetNewCurrentCulture()
{
  oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
  System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
}
//reset Current Culture back to the originale
void ResetCurrentCulture()
{
  System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
}

SOLUTION 2:


Another solution that could work, create a 1033 directory under Microsoft Office\Office11 (or your corresponding office-version), copy excel.exe to the 1033 directory, and rename it to xllex.dll.

Although you might solve the problem using one off these solutions, when you call the Excel object model in locales other than US English, the Excel object model can act differently and your code can fail in ways you may not have thought of. For example, you might have code that sets the value of a range to a date:

yourRange.Value2 = "10/10/09"

Depending on the locale this code can act differently resulting in Excel putting into the range any of the following values:

October 10, 2009 September 10, 2009 October 9, 2010

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • The solution 1 worked for me. In french the equiv of `SUM` is `SOMME`. I was saying ``SUM` via C# to my Excel translated in English. The formula was Ok but Excel said `#NAME`. After doubleclicking on the cell and pressing ENTER without any change, Excel was giving the formula result. Sending `SOMME` in C# outputed `SUM`. So, the solution 1 allowed me to send `SUM`without error. – Fabrice T Jul 12 '16 at 11:42
4

The meaning of the completely undocumented error 800A03EC (shame on Microsoft!) is something like "OPERATION NOT SUPPORTED".

It may happen

  • when you open a document that has a content created by a newer Excel version, which your current Excel version does not understand.
  • when you save a document to the same path where you have loaded it from (file is already open and locked)

But mostly you will see this error due to severe bugs in Excel.

  • For example Microsoft.Office.Interop.Excel.Picture has a property "Enabled". When you call it you should receive a bool value. But instead you get an error 800A03EC. This is a bug.
  • And there is a very fat bug in Exel 2013 and 2016: When you automate an Excel process and set Application.Visible=true and Application.WindowState = XlWindowState.xlMinimized then you will get hundreds of 800A03EC errors from different functions (like Range.Merge(), CheckBox.Text, Shape.TopLeftCell, Shape.Locked and many more). This bug does not exist in Excel 2007 and 2010.
Elmue
  • 7,602
  • 3
  • 47
  • 57
  • Can also happen if you are writing to a cell with a coordinate of zero. Cells are numbered 1 and up. – DustWolf Feb 25 '19 at 09:20
1

I had this problem when I was trying to use the range.AddComment() function. I was able to solve this by calling range.ClearComment() before adding the comment.

Jay
  • 11
  • 1
1

I got this when I forgot to unprotect workbook or sheet.

Makatun
  • 947
  • 10
  • 11
1

Using Dominic's answer I found the answer to my problem specifically was an invalid DateTiime in the source data before it was applied to the range. Somewhere between the database, .NET and Excel the conversion of the date defaulted down to "1/1/1899 12:00:00 AM". I had to check it and convert it to an empty string and it fixed it for me.

if (objectArray[row, col].ToString() == "1/1/1899 12:00:00 AM")
{
    objectArray[row, col] = string.Empty;
}

This is probably a pretty specific example but hopefully it will save somebody else some time if they are trying to track down a piece of invalid data.

aaron
  • 349
  • 3
  • 10
1

Excel Range index is None-Zero and start from 1.
If you call sheet.Rows[0] or sheet.Columns[0] or sheet.Cells[0] exception was thrown, because index is start from 1 and 0 is invalid index.

D.L.MAN
  • 990
  • 12
  • 18
0

I have encountered this error code when enumerating names and calling worksheet.get_Range(name). It seems to occur when the name does NOT apply to a range, in my case it is the name of a macro.

Jay
  • 10,200
  • 4
  • 28
  • 36
0

I ran to a similar error running Excel in VBA, what I've learned is that when I pull data from MSSQL, and then using get_range and .Value2 apply it's out of the range, any value that was of type uniqueidentifier (GUID) resulted in this error. Only when I cast the value to nvarcahr(max) it worked.

David
  • 5,882
  • 3
  • 33
  • 44
0

Interesting enough, this error also occurs, at time of opening when the .XLS? file is incorrectly formed or require repairs.

A hard to find error is to many rows on a .xls (old excel) file.

Test it: manually open the affected file with excel desktop .

I use automation to process a few hundred files daily, when this error show up, I notify the owner via mail and save the unprocessed file on a temporary location.

fcm
  • 1,247
  • 15
  • 28
0

Hi was Facing the same issue

Steps

  1. make sure you are accessing the excel file, not in read-only mode(protected mode) while trying edit and save changes.

  2. If it happens after that as well you can go to excel file-->Options-->Formulas and here disable the error checking(which is cause for almost most of the HRESULT errors)

dennis_ler
  • 659
  • 1
  • 9
  • 36
0

I found the answer to my problem. ((Excel.Range)worksheet.Cells[x, y]).Text, where x & y have to be greater than 0. (Starting from 1.)

-2

If you can copy the whole exception it would be much more better, but once I faced with this Exception and this is because the function calling from your dll file which I guess is Aspose.dll hasn't been signed well. I think it would be the possible duplicate of this

FYI, in order to find out if your dll hasn't been signed well you should right-click on that and go to the signiture and it will tell you if it has been electronically signed well or not.

Community
  • 1
  • 1
Ehsan
  • 4,334
  • 7
  • 39
  • 59