Sub ListFilesInFolderPart2(SourceFolderName As String, IncludeSubfolders As Boolean)
' lists information about the files in SourceFolder
' example: ListFilesInFolder "C:\FolderName\", True
On Err GoTo ERR_PROCESS:
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
Dim FileItem As Scripting.File
Dim r As Long
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(SourceFolderName)
r = Range("A65536").End(xlUp).Row + 1
For Each FileItem In SourceFolder.Files
' display file properties
Cells(r, 1).Formula = FileItem.Path ' & FileItem.Name
Cells(r, 2).Formula = FileItem.Size
Cells(r, 3).Formula = FileItem.Type
Cells(r, 4).Formula = FileItem.DateCreated
Cells(r, 5).Formula = FileItem.DateLastAccessed
Cells(r, 6).Formula = FileItem.DateLastModified
Cells(r, 7).Formula = FileItem.Attributes
Cells(r, 8).Formula = FileItem.ShortPath ' & FileItem.ShortName
Cells(r, 9).Formula = FileItem.Path
Cells(r, 10).Formula = FileItem.Name
'Cells(r, 11).Formula = PictureDimensions(FileItem.Path)
'Cells(r, 11).Formula = GetDetailsOf(FileItem.Path, 26)
Cells(r, 1).Activate
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
Cells(r, 1).Value, TextToDisplay:= _
Cells(r, 1).Value
Cells(r, 9).Activate
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
Cells(r, 1).Value, TextToDisplay:= _
Cells(r, 9).Value
Cells(r, 10).Activate
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
Cells(r, 1).Value, TextToDisplay:= _
Cells(r, 10).Value
r = r + 1 ' next row number
Next FileItem
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
ListFilesInFolderPart2 SubFolder.Path, True
DoEvents
Next SubFolder
End If
With Range("C1")
.Formula = "COMPLETED:" & Date & " " & Time()
.Font.Bold = True
.Font.Size = 12
End With
Range("B1").Select
Columns("A:j").AutoFit
Exit Sub
ExitGracefully:
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
If Err <> 0 Then
With Range("C1")
.Formula = "OOOPS: " & Err.Description
.Font.Bold = True
.Font.Size = 12
End With
End If
ActiveWorkbook.Saved = True
Exit Sub
ERR_PROCESS:
Debug.Print Err.Number, Err.Description
Resume ExitGracefully
End Sub