I found an excellent vba code to list all files in a directory onto an excel sheet. I am wondering is there a way of extending this so as it loops it will do a line count ("counta") on column "A" and return that along with the other items
Currently it returns the file name (Column A), Date Last Modified (Column B), File Size (Column C) - I would like to add the line count in Column D.
Any help would be greatly appreciated.
Sub TestListFilesInFolder()
Workbooks.Add ' create a new workbook for the file list
Range("A1").Formula = "File Name:"
Range("B1").Formula = "Date Last Modified:"
Range("C1").Formula = "Size:"
ListFilesInFolder "C:\raw_keywords\Google Keyword List\Vehicle", True
End Sub
Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As Boolean)
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
Dim FileItem As Scripting.File
Dim r As Long
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(SourceFolderName)
r = Range("A65536").End(xlUp).Row + 1
For Each FileItem In SourceFolder.Files
Cells(r, 1).Formula = FileItem.Path
Cells(r, 2).Formula = FileItem.DateLastModified
Cells(r, 3).Formula = FileItem.Size
r = r + 1
Next FileItem
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
ListFilesInFolder SubFolder.Path, True
Next SubFolder
End If
Columns("A:H").AutoFit
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
End Sub
Currently it returns the file name (Column A), Date Last Modified (Column B), File Size (Column C) - I would like to add the line count in Column D.
Any help would be greatly appreciated.
Sub TestListFilesInFolder()
Workbooks.Add ' create a new workbook for the file list
Range("A1").Formula = "File Name:"
Range("B1").Formula = "Date Last Modified:"
Range("C1").Formula = "Size:"
ListFilesInFolder "C:\raw_keywords\Google Keyword List\Vehicle", True
End Sub
Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As Boolean)
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
Dim FileItem As Scripting.File
Dim r As Long
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(SourceFolderName)
r = Range("A65536").End(xlUp).Row + 1
For Each FileItem In SourceFolder.Files
Cells(r, 1).Formula = FileItem.Path
Cells(r, 2).Formula = FileItem.DateLastModified
Cells(r, 3).Formula = FileItem.Size
r = r + 1
Next FileItem
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
ListFilesInFolder SubFolder.Path, True
Next SubFolder
End If
Columns("A:H").AutoFit
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
End Sub