HRESULT: 0x800A03EC on Worksheet.range
Asked Answered
W

28

31

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.

Weiner answered 17/8, 2011 at 21:31 Comment(6)
A little code snippet or a bit more context wouldn't hurt if you are looking for answersHobie
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.Weiner
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.Hobie
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.Weiner
can reproduce this error, see my answer belowHobie
Cannon, I have the same error but the solution doesn't workCharmeuse
H
28

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

Hobie answered 18/8, 2011 at 13:45 Comment(5)
Not always the case, I am having this issue with a .xlsx sheet.Rumen
@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.Rumen
@Rumen 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: #35841573Capita
@Rumen 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()Inspan
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)Striped
J
20

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.
Jokjakarta answered 1/11, 2012 at 10:11 Comment(4)
Re. #7: what is the name of the service to look for?Mckellar
I'm also doing the number 1- 4Mirtamirth
Rebooting the computer works also, and it might be a faster solution. It worked for me; I tried to follow the steps above, but I got lost on step 9.Manful
Also consider checking permissions; this error can issue if the current user does not have launch and activation permission.Subscription
K
19

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.

Kowloon answered 2/2, 2015 at 10:47 Comment(0)
P
14

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.

Pompous answered 11/2, 2013 at 17:29 Comment(1)
It is a bit funny, some of the numbers represent different errors, similar to an IDWarrant
E
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.

Episcopalism answered 7/11, 2012 at 15:33 Comment(0)
C
2

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

Cutthroat answered 23/10, 2012 at 5:17 Comment(0)
H
1

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.

Humility answered 17/8, 2011 at 22:25 Comment(4)
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.Weiner
Oh, that is weird. It worked on my test for very very large ranges.Humility
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].Weiner
Glad you got it figured out. You should post that as an answer and accept it so that people know this is resolved.Humility
W
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.

Weiner answered 18/8, 2011 at 16:10 Comment(3)
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.Hobie
Yes. Absolutely correct. And my answer is the solution to that issue if you are using Office 2007. Thank you.Weiner
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?Thirtyeight
P
1

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

wSheet.Rows(y).Style = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red)
Prescription answered 9/6, 2016 at 16:26 Comment(0)
L
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.

Liana answered 23/6, 2016 at 11:0 Comment(0)
P
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://mcmap.net/q/8775/-exception-from-hresult-0x800a03ec-error. 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).

Paintbox answered 2/1, 2018 at 16:3 Comment(0)
M
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.

Marjoram answered 3/1, 2019 at 17:39 Comment(1)
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.Whitsuntide
D
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
Defrayal answered 6/5, 2019 at 9:32 Comment(0)
U
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);
}
Usually answered 12/2, 2021 at 13:26 Comment(0)
D
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.

Disclimax answered 21/2, 2015 at 21:0 Comment(0)
S
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

Senaidasenalda answered 5/2, 2016 at 4:4 Comment(0)
M
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)
Monte answered 2/2, 2017 at 14:8 Comment(0)
T
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.

Truc answered 10/3, 2017 at 10:14 Comment(0)
P
0

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

Philous answered 29/5, 2017 at 8:56 Comment(0)
O
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

Orangeman answered 8/9, 2017 at 0:29 Comment(0)
C
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

Choke answered 25/4, 2018 at 7:40 Comment(0)
S
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()"

Speakeasy answered 17/4, 2019 at 19:39 Comment(0)
F
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.

Fleshings answered 30/9, 2019 at 7:9 Comment(0)
U
0

I ran in to the same error. For me it was while trying to set a CountIf and CountIfs respectively that I got the error.

After some trial an error I found out it was an issue I had with all formulas using multiple parameters.

It turns out that the parameter separator ";" (semicolon), which I use in excel is not the correct one for me to use in code behind. If I use "," (comma) in stead, the formula is correctly used. Note: When viewed in Excel afterwards, it is shown as ";" (semicolon).

My trial and error process included trying to set a bunch of different formulas, and this was the 'fix' I ended up with. I am running an English windows, but I am located in Denmark, I have no idea if there is some kind of localization involved with my issue.

CultureInfo.CurrentCulture.TextInfo.ListSeparator is ";", and this works correctly for separating validator rule values. Perhaps this is the reason why my parameter separator is something else.

Anyways; the formula could be wrong because you need to use a different parameter separator character.

Ummersen answered 28/7, 2021 at 8:14 Comment(0)
S
0

I had this same error code. Turns out a comment here helped me. Count does not start from 0. The commented out line was throwing this error.

string cell = (string)range.Cells[3, 3].Value; This line worked fine

string QuestionID = (string)range.Cells[1, 0].Value;This line threw this error

Stomatitis answered 22/12, 2021 at 17:21 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Afreet
O
0

I know this is old but I had the same error when trying to set a spreadsheet range as follows:

rngSumFormula = mxlWorksheet.Range(strFormulaRange)

There were plenty of mxlWorksheet.Range statements before this one but it failed every time. It turned out, after a ton of digging that the difference between my range value in strFormulaRange and the other values is that it had commas in the range i.e. "B2,C2,D2:E2". Before this statement all the ranges values simple had a colon i.e. "D2:E2".

So why was this an issue? Because I don't use comma as my default separator in Windows 10 instead I use a pipe character (|) as I deal with a lot of SQL bulk loads of description fields which contain lots of commas that aren't separators. Once I changed my default separator back to a comma my error disappeared.

This probably won't help very many people as I don't think separator changes are very common but since it was my solution I wanted to share. Just for reference you change your separator in Windows 10 here:

Region Settings>Additional Date, Time & Regional Settings>Change Date, Time or Number Formats>Additional Settings and then scroll down to List separator.

Olag answered 18/8, 2022 at 18:7 Comment(0)
B
0

For me the answer came when trying to post a Notes column in the Excel sheet. The sheet would not accept it. I kept getting this error. I thought it might be a certain character or something. If it is, I don't know what. So I just cut it off at 250. I don't know what the size limit actually is?!... but for my purpose in this report it's not really important:

The ones that are empty I've already filled with 'Missing.Value'.

            if (dr[c] != null && dr[c].ToString() != "")
            {
                string t = dr[c].ToString().Replace("\t", "").Replace("|", ":").Replace("/", "-").Replace("\n", " ").Trim();
                if (t.Length > 250)
                    t = t.Substring(0, 250);
                arr[r, c] = t;
            }
Bawd answered 23/5, 2023 at 21:26 Comment(0)
L
-1

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

Loci answered 1/12, 2017 at 9:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.