Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8525015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:51:09+00:00 2026-06-11T07:51:09+00:00

I just started working with VB.NET. In my application I will need to have

  • 0

I just started working with VB.NET. In my application I will need to have the exact number of used rows in an Excel file.

I had a look at this post Reading line count using VB.NET and I tried all the answers but I’ve never got the exact number of rows.

Could anybody help me out?

Hello in actually I work with SQL SERVER 2008 I tried this code

Imports System.Diagnostics.Process
Imports System.IO
Imports System.Data.DataTable
Imports Microsoft.Office.Tools
Imports Excel
Imports Microsoft.Office.Interop

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As  System.EventArgs) Handles Button1.Click
        Dim selectedFile As String = String.Empty

        OpenFileDialog1.ShowDialog()
        selectedFile = OpenFileDialog1.FileName

        If (selectedFile IsNot Nothing) Then
            ListBox1.Items.Add(selectedFile)

        End If
    End Sub
    
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim fullPath As String
        Dim fileResult As String
        Dim numRow As Integer
        fullPath = Path.GetFullPath(ListBox1.SelectedItem)

        fileResult = Path.GetFileName(fullPath)
        Dim file_count As Integer = File.ReadAllLines(fullPath).Length
        MsgBox(file_count)
    

but again the count is not correct, and I really do not know why!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:51:11+00:00Added an answer on June 11, 2026 at 7:51 am

    Hello finally I got the solution:

    Imports Microsoft.Office.Interop.Excel
    Imports System.Data.DataTable
    Imports Microsoft.Office.Interop
    
    private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim fullPath As String
        Dim fileResult As String
        Dim numRow As Integer
        fullPath = Path.GetFullPath(ListBox1.SelectedItem)
    
        fileResult = Path.GetFileName(fullPath)
    
        Dim obook As Excel.Workbook
        Dim oapp As Excel.Application
        oapp = New Excel.Application
        obook = oapp.Workbooks.Open(fullPath)
        numRow = 3
    
        While (obook.ActiveSheet.Cells(numRow, 1).Value IsNot Nothing)
            numRow = numRow + 1
        End While
    
        MsgBox(numRow)
    
    End Sub
    

    and you have to add the folowing references:

    Microsoft Excel 12.0 Library
    Microsoft Office 12.0 Library
    Microsoft Office Tools v9.0
    Microsoft visual Basic for application extensibility
    

    Hope it helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started working on an asp.net / C#.net application that is going to
I've just started working on a brownfield ASP.NET 2.0 Web Application. As with a
I have recently just started working with Lucene (specifically, Lucene.Net) and have successfully created
I am new to ASP and ASP.net. I have just started working on a
I have just started working on an existing Wicket application that uses Hibernate. I
Just started working with .NET and MVC(1). I'm having a problem wherein in my
I just started working on a small team of .NET programmers about a month
I just started working on a website that will help people understand what rappers
I have just started working on an open source project. The project is hosted
I have recently started working on a web application at a new company and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.