https://github.com/walter426/VbaUtilities/blob/master/FileSysUtilities.bas
Public Function CountRowsInText(file_name As String) As Long
On Error GoTo Err_CountRowsInText
Dim fso As Object
Dim File As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set File = fso.OpenTextFile(file_name, 1)
Dim RowCnt As Long
Dim str_line As String
RowCnt = 0
Do Until File.AtEndOfStream = True
RowCnt = RowCnt + 1
str_line = File.ReadLine
Loop
File.Close
Exit_CountRowsInText:
CountRowsInText = RowCnt
Exit Function
Err_CountRowsInText:
RowCnt = -1
Call ShowMsgBox(Err.Description)
Resume Exit_CountRowsInText
End Function
沒有留言:
張貼留言