[Solved] Counting the lines of several txt files [closed]


Try this code

Sub Loop_Through_Text_Files_Count_Lines()
Dim fso         As Object
Dim pth         As Object
Dim strFolder   As String
Dim strFile     As String
Dim r           As Long

With Application.FileDialog(msoFileDialogFolderPicker)
    If .Show Then strFolder = .SelectedItems(1) & "\" Else Exit Sub
End With

Set fso = CreateObject("Scripting.FileSystemObject")
strFile = Dir(strFolder & "*.txt")

Do While strFile <> ""
    r = r + 1
    Set pth = fso.OpenTextFile(strFile, 1)
    pth.ReadAll

    Cells(r, 1).Value = strFile
    Cells(r, 2).Value = pth.Line

    strFile = Dir
Loop
End Sub

3

solved Counting the lines of several txt files [closed]