I've made a code to get the path of the files in a particular directory. But, I would want the path of the files from other folders as well. Can someone please help me on what changes are required in order to get the path of the file from multiple directory. Thank you for your help in advance. Below is the VBA code:
Sub LoopThroughFolder()
Dim r As Integer 'Row as unique
r = 2 'Row 2
Sheets("sheet1").Select 'Selects the sheet 1
Range("A2:E5000").ClearContents 'Clears the contents on every run
Set FileSystemObject = CreateObject("Scripting.FileSystemObject") 'File System object created
Set FolderObj = FileSystemObject.getfolder("C:\Users\Yash") 'Directory
For Each FileObj In FolderObj.Files 'loop through files
If Not FileObj.Attributes And 2 Then 'Only show files that are not hidden
Cells(r, 1).Value = FileObj.Path 'Output
r = r + 1 'Next value = next cell
End If 'If it's hidden files it will not be considered in the output
Next FileObj 'All the files are selected
End Sub
Bookmarks