Solved

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

Posted on 2011-03-15
4
981 Views
Last Modified: 2013-11-08
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
0
Comment
Question by:RIAS
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:ElrondCT
ID: 35138534
Change to:

    Return xlWorksheet.UsedRange.Rows.Count
0
 

Author Comment

by:RIAS
ID: 35138601
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
0
 
LVL 20

Accepted Solution

by:
ElrondCT earned 500 total points
ID: 35138714
When I want a single cell, I don't bother with a range object:

       strCol = oSheet.Cells(intRow, intCol).Value

But I'm not sure why you're getting your error.
 
0
 

Author Closing Comment

by:RIAS
ID: 35138904
Cheers mate !!!Works like charm
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question