27

I am getting HRESULT: 0x800A03EC on Worksheet.range method. Number of rows are more than 70K. Office 2007.

Code:

Microsoft.Office.Interop.Excel.Range neededRange
    = currentWS.Range[cell.Cells[1, 1], cell.Cells[nRowCount, nColumnCount]];

Here my rowcount is more than 65530 . Breaks on this function. I have observed that it breaks only when row count goes more than 65530.

Cannon
  • 2,441
  • 10
  • 39
  • 81
  • 2
    A little code snippet or a bit more context wouldn't hurt if you are looking for answers – Eddy Aug 17 '11 at 21:44
  • `Microsoft.Office.Interop.Excel.Range neededRange = currentWS.Range[cell.Cells[1, 1], cell.Cells[nRowCount, nColumnCount]];` Here my rowcount is more than 66000. Column count is 18. Breaks on this function. – Cannon Aug 17 '11 at 21:50
  • Using excel 2010 i can get a range that size without a problem. Check if your problem is really with the Range method or that the cell.Cells[nRowCount, nColumnCount] is causing the exception. – Eddy Aug 17 '11 at 22:01
  • I tried Range method the other way around as k.schroeder31 has suggested `Microsoft.Office.Interop.Excel.Range neededRange = currentWS.Range["A1", ((Microsoft.Office.Interop.Excel.Range)currentWS.Cells[nRowCount, nColumnCount])]; `. But issue remains. – Cannon Aug 18 '11 at 13:16
  • can reproduce this error, see my answer below – Eddy Aug 18 '11 at 13:46
  • Cannon, I have the same error but the solution doesn't work – Cookie Monster Jan 15 '18 at 04:04

24 Answers24

27

This problem occurs if you are using a backwards compatible sheet (a .xls) instead of a .xlsx

To allow sheets to be opened in pre office 2007 version it can't contain more than 65k rows. You can check the number of rows in your sheet by using ctrl+arrowdown till you hit the bottom. If you try to get a range larger than that number of rows it will create an error

Eddy
  • 5,162
  • 20
  • 36
  • 18
    Not always the case, I am having this issue with a .xlsx sheet. – Alex Feb 26 '16 at 08:40
  • @user2179427 Unfortunately not, I had to compromise and take a different approach, what are you trying to achieve? I've done a lot of work with the Excel interop lately so I might be able to help. – Alex Mar 07 '16 at 12:05
  • @Alex I would like to write double values rounded to 2 decimal places to my worksheet in a for loop. Here is my question I have posted today: http://stackoverflow.com/questions/35841073/excel-exception-from-hresult-0x800a03ec-when-writing-to-a-excel-cell – user2179427 Mar 07 '16 at 12:08
  • @Alex Recently i migrated my excel project from 2010 to 2016 . when i am doing Sheet.Range("A1").Select(). Some times it's throwing the error, Some times it's working. I have activated the workbook and sheet . Error i am seeing is at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) at Microsoft.Office.Interop.Excel.Range.Select() – user1844634 Sep 13 '17 at 07:13
  • Note: This except can also be thrown when trying to write nothing to Excel. I had a `DataTable` that was set to a `stored procedure` in SQL Server. When trying to export that `DataTable` I was receiving this error. Turned out my `stored procedure` wasn't returning anything. (Posting for future searches) – Symon Oct 09 '18 at 15:40
19

We were receiving the same. The exception was

Stacktrace: at Microsoft.Office.Interop.Excel._Workbook.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object Text VisualLayout, Object Local)`

with an inner exception of

Exception from HRESULT: 0x800A03EC 2012-11-01 10:37:59`

We were able to resolve the problem with information from this post, which I quote here for convenience...

  1. Login to the server as a administrator.
  2. Go to "Start" -> "Run" and enter "taskmgr"
  3. Go to the process tab in task manager and check "Show Processes from all users"
  4. If there are any "Excel.exe" entries on the list, right click on the entry and select "End Process"
  5. Close task manager.
  6. Go to "Start" -> "Run" and enter "services.msc"
  7. Stop the service automating Excel if it is running.
  8. Go to "Start" -> "Run" and enter "dcomcnfg"
  9. This will bring up the component services window, expand out "Console Root" -> "Computers" -> "DCOM Config"
  10. Find "Microsoft Excel Application" in the list of components.
  11. Right click on the entry and select "Properties"
  12. Go to the "Identity" tab on the properties dialog.
  13. Select "The interactive user."
  14. Click the "OK" button.
  15. Switch to the services console
  16. Start the service automating Excel
  17. Test you application again.
Mo Patel
  • 2,191
  • 4
  • 21
  • 34
John Fitzpatrick
  • 3,857
  • 4
  • 44
  • 69
16

I encountered this issue.

Discovered that somewhere in my code I was asking it to count starting from 0 (as you would in a C# code).

Turns out Excel counting starts at 1.

Cald
  • 171
  • 1
  • 4
13

Looking at the various responses above, and drawing on my own recent experience (I got this error code doing something completely unrelated -- setting Application.Calculation) I conclude that the same error code is used to indicate multiple unrelated problems. So @Garreh you should probably be asking a new question (not that anyone will be able to help based on the error code alone). I've seen the same thing working with Word interop from C#, where the same HRESULT seems to be used for almost every kind of error. I've never found any satisfactory Microsoft documentation on what the codes might mean.

Hugh W
  • 219
  • 1
  • 6
  • 16
5

This could also be caused if you have no room on the partition you are saving to.

I checked my HD and foind it was maxed. Moving some un-needed files to a different partition resolved my problem.

Patrickmoe
  • 51
  • 1
  • 1
3

Simply, the excel file is corrupt. Best solution is change/repair the file.(make a copy of the existing file and rename it)

Sonio
  • 39
  • 1
1

Just FYI, got the error trying to apply row style....

wSheet.Rows(y).Style = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red)
htm11h
  • 1,655
  • 8
  • 45
  • 96
1

Not being able to reply to/endorse this answer, so posting here:

Indeed, the format of the source/destination ranges when moving data from one range to another might cause this error as well.

In my case, the range I wanted to copy contained a date formatted column, and the column contained one cell with an invalid date value (it was not even formatted due to its value, which was a negative integer). So the copy operation between the two ranges was halting at the said cell yielding the very error message discussed here.

The solution in my case was to use Range.Value2 instead of Range.Value, which caused Excel to bypass formatting the cell as a date (more details here). However, this will render your date and time columns to display as integers and decimals. You will, however, be able to change the formats to the desired ones if you know where to expect the date and time values by setting their Range/Column/Cell.NumberFormat property accordingly.

Community
  • 1
  • 1
1

This isn't directly answering the question, but I was getting this error when opening an xlsx file. The problem was that I was using forward slashes in my file path. See also https://stackoverflow.com/a/24635904/5932003. It used to work in previous versions of Excel, but not with Version 1711 (Build 8730.2127).

I was able to diagnose the problem using IDispatch->Invoke(..., EXCEPINFO, ...). The EXCEPINFO object contained a useful description of what went wrong. I was in C++ land, but I suspect that C# code similar to this SO post will do the trick: Packaging IDispatch Invoke with Parameters in C# (with DISPPARAMS).

kostasvs
  • 146
  • 2
  • 8
1

I received this error code 0x800A03EC when trying to save an Excel file created within my .Net application in VS 2017. I changed the Excel.Application object property Visible=True and let it run until the point of failure. Tried to finish the steps manually in Excel and then discovered I could not save the file because of missing folder permissions. I added the Write permission to the folder, and the error went away.

MarkF
  • 113
  • 7
  • Had the same error on a permissions issue. Program was supposed to run daily to create/update a file but only worked once because it created a file in a location that other users couldn't overwrite after initial creation. – nvuono Jun 07 '19 at 15:11
1

For others like me, who have the same exception:

It can also happen if you try to pass a null value instead of Missing.Value (or Type.Missing)

e.g.

Worksheet worksheet = ...;
return worksheet.Range["A1", null]; //This call generates the error 0x800A03EC

return worksheet.Range["A1", Missing.Value]; //This works correctly
Ruben Giaquinto
  • 381
  • 1
  • 14
1

in 2021, when i got this problem. the reason actually is:

for a Excel range or cell, i was trying to add/delete comment directly without checking whether there is a comment binding with it or not.

error code is:

if ( comments_string.Length != 0)
{     range.AddComment( comments_string);
}

working code is:

if ( comments_string.Length != 0)
{     if (range.Comment != null) range.Comment.Delete();
     range.AddComment(comments_string);
}
Mike Xue
  • 21
  • 3
1

I don't understand the issue. But here is the thing that solved my issue.

Go to Excel Options > Save > Save Files in this format > Select "Excel Workbook(*.xlsx)". Previously, my WorkBooks were opening in [Compatibuility Mode] And now they are opening in normal mode. Range function works fine with that.

Cannon
  • 2,441
  • 10
  • 39
  • 81
  • 2
    The why is/was in my answer below. Compat mode implies a limit of 65k rows otherwise the sheets can't be openend in older excel versions. – Eddy Aug 21 '11 at 18:52
  • Yes. Absolutely correct. And my answer is the solution to that issue if you are using Office 2007. Thank you. – Cannon Aug 22 '11 at 05:06
  • I am using office 2010 (interlop excel 14) and I am trying to build an xls file, and encountering this error when retrieving cells. Any ideas? – Gaʀʀʏ Jul 22 '12 at 23:49
0

I had an error with exact code when I tried to assigned array of cells to range.Value. In my case it was the problem with wrong data format. The cell's data format was set as DATE but the user made an error and instead of "20.02.2013" entered date "20.02.0213". The Excel's COM object refused taking year '0213' and threw exception with this error.

Evgeny Sobolev
  • 438
  • 4
  • 12
0

I also faced the same issue, when I was developing a application which exports project contents into excel file.

I could not found the resolution in forums for my problem, then I check the maximum capacity of excel and found below link which says

"Worksheet size 1,048,576 rows by 16,384 columns" and this was the issue in my case, I was exporting more than that rows. Refer below link for details

http://answers.microsoft.com/en-us/office/forum/office_2013_release-excel/with-excel-2013how-many-rows-will-this-contain/271264fb-3ab8-4c5b-aa0d-7095c5ac6108

Regards Prashant Neve

0

I had the same error code when executing the following statement:

sheet.QueryTables.Add("TEXT" & Path.GetFullPath(fileName), "1:1", Type.Missing)

The reason was the missing semicolon (;) after "TEXT".

Here is the correct one:

sheet.QueryTables.Add("TEXT;" & Path.GetFullPath(fileName), "1:1", Type.Missing)
0

I got this exception because I typed:

ws.get_Range("K:K").EntireColumn.AutoFit();
ws.get_Range("N:N").EntireColumn.AutoFit();
ws.get_Range("0:0").EntireColumn.AutoFit();

See a mistake? Hint: Excel is accepting indexing from 1, but not from 0 as C# does.

Pedro
  • 1
  • 1
0

I got this error because I tried to rename a sheet with too many characters

Blobby
  • 1
0

I agree with Hugh W post "I conclude that the same error code is used to indicate multiple unrelated problems"

Other posts have not mentioned that this error occurs frequently if the worksheet is locked. While I haven't tested every scenario, it seems that anything that you can not do in excel when a worksheet is locked with throw this error if you attempt to do it via VSTO/Com while the sheet is locked. E.G. Changing any style artifact (font, font size, colour, underline), changing the Excel Validation, changing the column widths, row heights, formulas

JimbobTheSailor
  • 887
  • 7
  • 16
0

I resolved this issue by using the code below. Please do not use other parameters in these functions.

mWorkBook = xlApp.Workbooks.Open(FilePath)

mWorkBook.Save();

RESOLVED

xoxel
  • 1,390
  • 2
  • 15
  • 28
0

Seems like this i s a pretty generic error for "something went wrong" with the operation you attempted. I have observed that will also occur if you have a formula error and are assigning that formula into a cell. E.g. "=fubar()"

Dan Sorak
  • 91
  • 5
0

I've come across it several different times and every time it was always some error with either duplicating a tab name or in this current case it just occurred because I simply had a typo in the get_Range where I tried to get a Cell by number and number instead of the letter and number.
Drove me crazy because the error pointed me to a few lines down but I had commented out all of the creation of the other sheets above the "error line" and the ones in the line and below were created with no issue.
Happened to scan up a few lines above and saw that I put 6 + lastword, C + lastrow in my get_Range statement and of course you can't have a cell starting with a number it's always letter than number.

Dino
  • 6,207
  • 8
  • 28
  • 62
0

EDIT: THIS IS WAY BETTER!!! You don't need that old function, sorry. Just do as follows:

Microsoft.Office.Interop.Excel.Range neededRange = currentWS.Range["A1", ((Microsoft.Office.Interop.Excel.Range)currentWS.Cells[nRowCount, nColumnCount])];

That should work like a charm. And for future reference, put the relevant code that you are using inside of your question. Don't make people ask for it in comments. I imagine that's why you got downvoted.

k.schroeder31
  • 771
  • 1
  • 7
  • 14
  • I tried your ay, but its still the same exception. So I dont think it has anything to do with the way I am suing Range function. – Cannon Aug 18 '11 at 13:14
  • Oh, that is weird. It worked on my test for very very large ranges. – k.schroeder31 Aug 18 '11 at 13:43
  • I don't understand the issue. But here is the thing that solved my issue. Go to Excel Options > Save > Save Files in this format > Select "Excel Workbook(*.xlsx)". Previously, my WorkBooks were opening in [Compatibuility Mode]. – Cannon Aug 18 '11 at 15:35
  • 1
    Glad you got it figured out. You should post that as an answer and accept it so that people know this is resolved. – k.schroeder31 Aug 18 '11 at 15:37
-1

This type of error can also occur when the excel file is corrupted for some reason

Arun
  • 13
  • 7