How to get the last modified file in a directory using VBA in Excel 2010

前端 未结 1 1348
南方客
南方客 2021-01-19 15:36

Im looking for a way to do this in Excel 2010 using VBA.

It used to be possible in Excel 2003 using the Application.FileSearch method, but this has be depreciated. (

相关标签:
1条回答
  • 2021-01-19 16:17

    If using the FileSystemObject is acceptable, you could use the method described here.

    To summarize:

    Dim fso As Scripting.FileSystemObject
    Dim fol As Scripting.Folder
    Dim fdr As Scripting.Folder
    Dim fil As Scripting.File
    Dim flc As Scripting.Folders
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fol = fso.GetFolder("YourPathName")
    Set flc = fol.SubFolders
    
    For Each fdr In flc
      For Each fil In fdr.Files
            Debug.Print fil.DateLastModified
      Next fil
    Next fdr
    
    Set fso = Nothing
    Set fol = Nothing
    Set flc = Nothing
    
    0 讨论(0)
提交回复
热议问题