Link to home
Start Free TrialLog in
Avatar of RIAS
RIASFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to handle System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC.

Hi,
Getting an error when trying to count rows in excel sheet by this function
Public Function GetColumnRowCount(ByVal col As Integer, ByVal xlWorksheet As Object) As Integer
             Return xlWorksheet.Cells(xlWorksheet.Rows.Count, col).End(-4162).Row
           
    End Function


Created excel application as follows:
   xlApp = CreateObject("Excel.Application")
                        FlagGetObj = True
                        xlApp.visible = False
                        xlApp.displayalerts = False
                        xlWB = xlApp.Workbooks.Open(workbook)    ' change the name of the sheet you require
                        Application.DoEvents()
                        xlWS = xlWB.Worksheets(ExcelSheetName)
                        xlWS.Activate()
                        xlApp.visible = True
                        k = GetColumnRowCount(col, xlWS) 'get number of records in excel sheet
                 
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

what -4162 means?
Avatar of RIAS

ASKER

This  was the code suggested by one of the mentor here.It did work initially but donno why this error is poping up now

Cheers
what's wrong with xlWorksheet.Cells.Count?
sorry, use UsedRange:

xlWorksheet.UsedRange.Rows.Count
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

Will try mate and come back ..Cheers
Avatar of RIAS

ASKER

Fantastic mate...Worked like a charm...
Avatar of RIAS

ASKER

Hi,

Getting error on
xlApp.Cells(h, .Pos).VALUE

Any suggestions?
run debugger and check xlApp.Cells(h, .Pos)
verify 'h' and '.pos' are in range