Public
Sub
main()
Dim
Pfad
As
String
Pfad =
"C:\Users\hhwjanse\Desktop\Test.txt"
Debug.Print count_lines(Pfad)
End
Sub
Private
Function
count_lines(
ByVal
sPfad
As
String
)
As
Long
Dim
fso
As
Object
Dim
stream
As
Object
Set
fso = CreateObject(
"Scripting.FileSystemObject"
)
If
Not
fso.FileExists(sPfad)
Then
Set
fso =
Nothing
count_lines = 0
MsgBox
"Datei "
& sPfad &
" existiert nicht."
Exit
Function
End
If
Set
stream = fso.OpenTextFile(sPfad, 1, 0)
Dim
l
As
Long
Do
While
Not
stream.AtEndOfStream
l = l + 1
stream.ReadLine
Loop
stream.Close
Set
fso =
Nothing
count_lines = l
End
Function