My VBA code below searches for all files in my Drive C: and list them in Sheet(1). Now, I am tasked to find specific .txt files only. I have tried modifying the code but to no success. I was thinking it has something to do with the ObjFile.
Sub ListAllFiles()
Dim ObjFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = ObjFSO.GetFolder("C:\")
Call getfiledetails(objFolder)
End Sub
Function getfiledetails(objFolder As Scripting.Folder)
Dim objFile As Scripting.File
Dim nextRow As Long
Dim objSubFolder As Scripting.Folder
nextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
For Each objFile In objFolder.Files
On Error Resume Next
Cells(nextRow, 1) = objFile.Name
Cells(nextRow, 2) = objFile.Path
Cells(nextRow, 3) = objFile.Type
Cells(nextRow, 4) = objFile.DateCreated
Cells(nextRow, 5) = objFile.DateLastModified
nextRow = nextRow + 1
Next objFile
For Each objSubFolder In objFolder.SubFolders
Call getfiledetails(objSubFolder)
Next
End Function
Any Help would be appreciated