Excel VBA using FileSystemObject to list file last date modified

前端 未结 1 642
滥情空心
滥情空心 2020-12-03 19:39

this is my first time asking question so hopefully I\'m following protocol. This is in reference to \"get list of subdirs in vba\" get list of subdirs in vba.

I foun

相关标签:
1条回答
  • 2020-12-03 20:14

    Try this code :

    Sub ListFilesinFolder()
    
        Dim FSO As Scripting.FileSystemObject
        Dim SourceFolder As Scripting.Folder
        Dim FileItem As Scripting.File
    
        SourceFolderName = "C:\Users\Santosh"
    
        Set FSO = New Scripting.FileSystemObject
        Set SourceFolder = FSO.GetFolder(SourceFolderName)
    
        Range("A1:C1") = Array("text file", "path", "Date Last Modified")
    
        i = 2
        For Each FileItem In SourceFolder.Files
            Cells(i, 1) = FileItem.Name
            Cells(i, 2) = FileItem
            Cells(i, 3) = FileItem.DateLastModified
            i = i + 1
        Next FileItem
    
        Set FSO = Nothing
    
    End Sub
    
    0 讨论(0)
提交回复
热议问题