Hello,
I have been researching for the past week to see if a VBA code exists that can meet my request. So far, I found a VBA that has met 90%. My last request is to see if each file found in each subfolder can list in column D the 'datelastmodified'. Any help is appreciated!
Thanks
Option Explicit
Public Sub Hierarchical_Folders_and_Files_Listing()
Dim startFolderPath As String
Dim startCell As Range
startFolderPath = "C:\"
Set startCell = Sheets("Sheet1").Range("A11")
startCell.Parent.Cells.Clear
List_Folders_and_Files startFolderPath, startCell
End Sub
Private Function List_Folders_and_Files(folderPath As String, destCell As Range) As Long
Static FSO As Object
Dim thisFolder As Object, subfolder As Object
Dim fileItem As Object
Dim n As Long
If FSO Is Nothing Then Set FSO = CreateObject("Scripting.FileSystemObject")
Set thisFolder = FSO.GetFolder(folderPath)
'Add hyperlink for this folder
destCell.Parent.Hyperlinks.Add Anchor:=destCell, Address:=thisFolder.Path, TextToDisplay:=thisFolder.Name
'List subfolders and files in this folder
For Each subfolder In thisFolder.Subfolders
Set destCell = destCell.Offset(0, 1)
Set destCell = destCell.Offset(List_Folders_and_Files(subfolder.Path, destCell), -1)
Next
'Add hyperlink for each file in this folder
n = 0
For Each fileItem In thisFolder.Files
destCell.Offset(n, 1).Parent.Hyperlinks.Add Anchor:=destCell.Offset(n, 1), Address:=fileItem.Path, TextToDisplay:=fileItem.Name
n = n + 1
Next
List_Folders_and_Files = n
End Function
Bookmarks