Greetings one and all
Everyone must start somewhere so I choose to start on this old post since it happens to applicable to my stumbling block. I too needed to list all the files, folders and subfolders in a given directory and was able to find a pair of macros on the web which gave me most of what I needed (plagiarism is a wonderful thing) and then with a bunch of modification I came up with the macros below. My problem is in the second macro (ListFilesInFolder). I have been unable to get Microsoft to give up the file "owner" (Person who created the file) to my spreadsheet. I can see it just fine when I am in that folder, I just can't get it into my excel file. The line that is giving me the trouble is:
Cells(r, 6).Formula - FileItem.Owner
Does anyone know what I need to do to make this work?
Randy P
Here are the macros:
Sub TestListFilesInFolder()
' Workbooks.Add ' create a new workbook for the file list
' add headers
'Clear out existing data
ActiveWindow.Panes(1).Activate
Columns("A:S").Select
Selection.Delete Shift:=xlToLeft
'Set column headers
With Range("A1")
.Font.Bold = True
.Font.Size = 12
End With
Range("A1").Formula = "File Name:"
Range("B1").Formula = "Path:"
Range("C1").Formula = "File Size:"
Range("D1").Formula = "Date Created:"
Range("E1").Formula = "Date Last Modified:"
Range("F1").Formula = "Owner:"
Range("H1").Formula = "Path:"
Range("I1").Formula = "File:"
Range("I1").Formula = "File:"
Range("J1").Formula = "Programmer:"
Range("K1").Formula = "Charged Out:"
Range("L1").Formula = "Update Date:"
Range("M1").Formula = "Days old:"
Range("N1").Formula = "EC1:"
Range("O1").Formula = "EC2:"
Range("P1").Formula = "EC3:"
Range("A1:P1").Font.Bold = True
Range("A2:P2500").Font.Bold = False
'Add comments
Range("N1").Select
Selection.ClearComments
Range("O1").Select
Selection.ClearComments
Range("N1").AddComment
Range("N1").Comment.Visible = False
Range("N1").Comment.Text Text:="Is this charged out" & Chr(10) & "in MOM?" & Chr(10) & ""
Range("N1").Select
Range("O1").AddComment
Range("O1").Comment.Visible = False
Range("O1").Comment.Text Text:="Has it been charged out" & Chr(10) & "more than 30 days?" & Chr(10) & ""
Range("O1").Select
ListFilesInFolder "M:\NCW\", True
End Sub
Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As Boolean)
' lists information about the files in SourceFolder
' example: ListFilesInFolder "C:\FolderName\", True
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.Name
Cells(r, 2).Formula = FileItem.Path
Cells(r, 3).Formula = FileItem.Size
Cells(r, 4).Formula = FileItem.DateCreated
Cells(r, 5).Formula = FileItem.DateLastModified
' Cells(r, 6).Formula = FileItem.Owner
r = r + 1 ' next row number
Next FileItem
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
ListFilesInFolder SubFolder.Path, True
Next SubFolder
End If
Columns("A:G").ColumnWidth = 4
Columns("H:I").AutoFit
Columns("J:L").ColumnWidth = 12
Columns("M:P").ColumnWidth = 8
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
ActiveWorkbook.Saved = True
End Sub
Bookmarks