Option Explicit
[B]Sub TestListFolders[/B]()
Dim Fldr As Variant
Application.ScreenUpdating = False
AddWorkBook
For Each Fldr In Split(FoldersToSearch, ",")
ListFolders CStr(Fldr), True
Next
Application.ScreenUpdating = True
End Sub
[B]Function FoldersToSearch[/B]() As String
Const F1 = "[COLOR=#ff0000]C:\TestArea[/COLOR]"
Const F2 = "[COLOR=#ff0000]C:\Program Files\internet explore[/COLOR][COLOR=#ff0000]r[/COLOR]"
Const F3 = [COLOR=#ff0000]"C:\Program Files\Mozilla Firefox[/COLOR]"
Const F4 = "[COLOR=#ff0000]C:\Users\yongle\Desktop[/COLOR]"
Const F5 = ""
Const F6 = ""
Dim FolderString As String
[COLOR=#000080]FoldersToSearch [/COLOR]= [COLOR=#ff0000]F1[/COLOR] & "," & [COLOR=#ff0000]F2[/COLOR] & "," & [COLOR=#ff0000]F3[/COLOR] & "," & [COLOR=#ff0000]F4[/COLOR]
End Function
[B]Sub AddWorkBook[/B]()
Workbooks.Add
' add headers
With Range("A1")
.Formula = "Folder contents": .Font.Bold = True: .Font.Size = 12
End With
With Range("A3:G3")
.Value = Split("Folder Path,Folder Name,Size,Subfolders:,Files,Short Name,Short Path", ",")
.Font.Bold = True
End With
End Sub
[B]Sub ListFolders[/B](SourceFolderName As String, IncludeSubfolders As Boolean)
' lists information about the folders in SourceFolder
' example: ListFolders "C:\", True
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
Dim r As Long
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(SourceFolderName)
On Error Resume Next 'line added for "Permission Denied" errors
r = Range("A" & Rows.count).End(xlUp).Row + 1
With SourceFolder ' display folder properties
Cells(r, 1).Resize(, 7) = Array(.Path, .Name, .Size, .SubFolders.count, .Files.count, .ShortName, .ShortPath)
End With
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
ListFolders SubFolder.Path, True
Next SubFolder
Set SubFolder = Nothing
End If
Columns("A:G").AutoFit
Set SourceFolder = Nothing
Set FSO = Nothing
End Sub