RIAS
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(xlWorksh eet.Rows.C ount, col).End(-4162).Row
End Function
Created excel application as follows:
xlApp = CreateObject("Excel.Applic ation")
FlagGetObj = True
xlApp.visible = False
xlApp.displayalerts = False
xlWB = xlApp.Workbooks.Open(workb ook) ' change the name of the sheet you require
Application.DoEvents()
xlWS = xlWB.Worksheets(ExcelSheet Name)
xlWS.Activate()
xlApp.visible = True
k = GetColumnRowCount(col, xlWS) 'get number of records in excel sheet
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(xlWorksh
End Function
Created excel application as follows:
xlApp = CreateObject("Excel.Applic
FlagGetObj = True
xlApp.visible = False
xlApp.displayalerts = False
xlWB = xlApp.Workbooks.Open(workb
Application.DoEvents()
xlWS = xlWB.Worksheets(ExcelSheet
xlWS.Activate()
xlApp.visible = True
k = GetColumnRowCount(col, xlWS) 'get number of records in excel sheet
what -4162 means?
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
Cheers
ASKER
what's wrong with xlWorksheet.Cells.Count?
sorry, use UsedRange:
xlWorksheet.UsedRange.Rows .Count
xlWorksheet.UsedRange.Rows
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Will try mate and come back ..Cheers
ASKER
Fantastic mate...Worked like a charm...
ASKER
Hi,
Getting error on
xlApp.Cells(h, .Pos).VALUE
Any suggestions?
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
verify 'h' and '.pos' are in range