Hello,
i have a code that i found online and modified it a little for my needs. the code is mappig folder and subfolder in a spesific path.
when it comes to a fold with no view permission its stoped.
can anyone help me with modifiing the code so it will map the folder name and move on to the next?
Thank you
Global startFolderPath As String
Public Sub Hierarchical_Folders_and_Files_Listing2()
Dim startFolderPath As String
Dim startCell As Range
Dim n As Long
startFolderPath = Sheet1.Cells(3, 6)
With Sheets("Sheet1")
ActiveSheet.Range("A1:D5000").Value = Delete
.Activate
Set startCell = .Range("A1")
End With
n = List_Folders_and_Files2(startFolderPath, startCell)
End Sub
Private Function List_Folders_and_Files2(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 in this folder
If destCell.Column > Sheet1.Cells(4, 6) Then GoTo here
n = 0
For Each subfolder In thisFolder.SubFolders
n = n + 1 + List_Folders_and_Files2(subfolder.Path, destCell.Offset(n + 1, 1))
Next
here:
'Add hyperlink for each file in this folder
List_Folders_and_Files2 = n
End Function
Bookmarks