Hi All,
I am trying to modify some VBA code I got from a YouTuber so that I can take the folder path that they enter and use it in the below code. I am a novice VBA'er so would greatly appreciate if someone can help me out with the correct coding.
I am trying to modify some VBA code I got from a YouTuber so that I can take the folder path that they enter and use it in the below code. I am a novice VBA'er so would greatly appreciate if someone can help me out with the correct coding.
VBA Code:
Sub ssFav()
Dim objGetPath As String
GetPath = InputBox("What’s the folder path that you want to search within?")
Range("C3").Value = GetPath
End Sub
Sub ListAllFiles()
Dim objFSO As Scripting.FileSystemObject
'objFSO is the File System object
Dim objFile As Scripting.File
Dim objTargetPath As String
'Set objTargetPath = ???
Set objFSO = CreateObject("Scripting.FileSyestemObject")
Set objFolder = objFSO.GetFolder("TargetPath")
'need to input parent folder file path above
Call GetFileDetails(objFolder)
End Sub
Function GetFileDetails(objFolder As Scripting.Folder)
Dim objFolder As Scripting.Folder
Dim nextRow As Long
Dim objSubFolder As Scripting.Folder
nextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
For Each objFile In objFolder.Files
Cells(nextRow, 1) = objFile.Name
Cells(nextRow, 2) = objFile.Path
Cells(nextRow, 3) = objFile.Size
Cells(nextRow, 4) = objFile.Type
Cells(nextRow, 5) = objFile.DateCreated
Cells(nextRow, 6) = objFile.DateLastModified
nextRow = nextRow + 1
Next
For Each objSubFolder In objFolder.SubFolders
Call GetFileDetails(objSubFolder)
Next
End Function
Last edited by a moderator: