Hello Pero and Jubinell,
Excellent catch on the missing macro Jubinell! I wrote the code and completely missed the obvious. Here is the full code with the corrections.
Calling Macro
Sub Macro1()
ListFilesInFolder Range("C3"), True
End Sub
List Files In Folder Macro
Sub ListFilesInFolder(ByVal SourceFolderName As String, ByVal IncludeSubfolders As Boolean)
Dim FSO As Object
Dim SourceFolder As Object
Dim SubFolder As Object
Dim FileItem As Object
Dim R As Long
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = FSO.GetFolder(SourceFolderName)
'Find last row that has data
R = Cells.Find("*", , xlValues, xlWhole, xlByRows, xlPrevious, False).Row
'Display file properties in the next row in columns "J:O"
For Each FileItem In SourceFolder.Files
R = R + 1
Cells(R, 10) = FileItem.Name
Cells(R, 11) = FileItem.Path
Cells(R, 12) = FileItem.Size
Cells(R, 13) = FileItem.DateCreated
Cells(R, 14) = FileItem.DateLastModified
Cells(R, 15) = GetFileOwner(SourceFolder.Path, FileItem.Name)
Next FileItem
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
ListFilesInFolder SubFolder.Path, True
Next SubFolder
End If
Columns("J:O").AutoFit
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
ActiveWorkbook.Saved = True
End Sub
Get File Owner Macro
Function GetFileOwner(ByVal FilePath As String, ByVal FileName As String)
Dim objFolder As Object
Dim objFolderItem As Object
Dim objShell As Object
FileName = StrConv(FileName, vbUnicode)
FilePath = StrConv(FilePath, vbUnicode)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(StrConv(FilePath, vbFromUnicode))
If Not objFolder Is Nothing Then
Set objFolderItem = objFolder.ParseName(StrConv(FileName, vbFromUnicode))
End If
If Not objFolderItem Is Nothing Then
GetFileOwner = objFolder.GetDetailsOf(objFolderItem, 8)
Else
GetFileOwner = ""
End If
Set objShell = Nothing
Set objFolder = Nothing
Set objFolderItem = Nothing
End Function
Bookmarks