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

asked on

Count number of excel rows +excel 2007 onwards+vb.net 2005

Hi,
I had a previous code to count number of rows in excel 2003 version sheet.But it errors in 2007.Any suggestions


   Public Function GetColumnRowCount(ByVal col As Integer, ByVal xlWorksheet As Object, ByVal xlApp As Object) As Integer
      Try
         Return xlWorksheet.Cells(xlWorksheet.Rows.Count, col).End(-4162).Row
      Catch ex As Exception
         AddMessage(ex.ToString)
      End Try
   End Function

Error:
System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
Avatar of ElrondCT
ElrondCT
Flag of United States of America image

Change to:

    Return xlWorksheet.UsedRange.Rows.Count
Avatar of RIAS

ASKER

Cheers I changed that and it works great.
But any suggestion on why it fails on
 Dim oRange As Excel.Range
oRange(1, 1).Value

 Excel.Range  is the interop excel reference.

Same error
System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
ASKER CERTIFIED SOLUTION
Avatar of ElrondCT
ElrondCT
Flag of United States of America 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

Cheers mate !!!Works like charm