• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1180
  • Last Modified:

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
                 
0
RIAS
Asked:
RIAS
  • 5
  • 5
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
what -4162 means?
0
 
RIASAuthor Commented:
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
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Meir RivkinFull stack Software EngineerCommented:
what's wrong with xlWorksheet.Cells.Count?
0
 
Meir RivkinFull stack Software EngineerCommented:
sorry, use UsedRange:

xlWorksheet.UsedRange.Rows.Count
0
 
Meir RivkinFull stack Software EngineerCommented:
if your excel table has 5 columns and 12 rows then:
xlWorksheet.UsedRange.Count = 60

xlWorksheet.UsedRange.Rows.Count = 12

xlWorksheet.UsedRange.Columns = 5
0
 
RIASAuthor Commented:
Will try mate and come back ..Cheers
0
 
RIASAuthor Commented:
Fantastic mate...Worked like a charm...
0
 
RIASAuthor Commented:
Hi,

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

Any suggestions?
0
 
Meir RivkinFull stack Software EngineerCommented:
run debugger and check xlApp.Cells(h, .Pos)
verify 'h' and '.pos' are in range
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now