HRESULT: 0x800A03EC on Worksheet.range

前端 未结 23 2092
Happy的楠姐
Happy的楠姐 2020-11-22 07:42

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

Code:

Microsoft.Office.Interop.Excel.Range         


        
相关标签:
23条回答
  • 2020-11-22 08:18

    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

    0 讨论(0)
  • 2020-11-22 08:20

    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.

    0 讨论(0)
  • 2020-11-22 08:22

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

    0 讨论(0)
  • 2020-11-22 08:23

    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

    0 讨论(0)
  • 2020-11-22 08:25

    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

    0 讨论(0)
  • 2020-11-22 08:27

    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.

    0 讨论(0)
提交回复
热议问题