Results 1 to 6 of 6

List files in folder

Threaded View

scubajon List files in folder 05-29-2008, 05:57 PM
Leith Ross Hello scubajon, I modified... 05-30-2008, 01:15 AM
scubajon Thanks Leith It will be a... 06-02-2008, 05:10 PM
scubajon Leith I put it in place, ran... 06-04-2008, 03:57 PM
jamessmith1330 Re: List files in folder 04-09-2015, 07:34 AM
Fotis1991 Re: List files in folder 04-09-2015, 07:56 AM
  1. #1
    Registered User
    Join Date
    05-28-2008
    Posts
    3

    List files in folder

    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
    Last edited by VBA Noob; 05-29-2008 at 05:59 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1