Thursday, February 3, 2011

Find the number of lines in text file


Function NoOfLineInTextFile() As Integer
      Dim objFSO, strTextFile, strData, arrLines, LineCount
      Const ForReading = 1
      strTextFile = "d:\StringFile.txt"
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      strData = objFSO.OpenTextFile(strTextFile, ForReading).ReadAll
      arrLines = Split(strData, vbCrLf)
      LineCount = UBound(arrLines) + 1
      Set objFSO = Nothing
      MsgBox "Number of lines available in : " & LineCount
      NoOfLineInTextFile = LineCount
End Function

No comments: