I am getting HRESULT: 0x800A03EC on Worksheet.range method. Number of rows are more than 70K. Office 2007.
Code:
Microsoft.Office.Interop.Excel.Range
I got this error because I tried to rename a sheet with too many characters
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.
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()"
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.
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)
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.