4

我正在寻找一种使用 VBA 在 Excel 2010 中执行此操作的方法。

它曾经在 Excel 2003 中使用 Application.FileSearch 方法成为可能,但它已被贬低。(见下文)

Dim sFileName As String

sFileName = ""
With Application.FileSearch
    .NewSearch
    .LookIn = sDir
    .Filename = "*.*"
    .Execute msoSortByLastModified, msoSortOrderDescending

    If .FoundFiles.Count > 0 Then sFileName = .FoundFiles(1)

End With

任何想法如何在 Excel 2010 中执行此操作?

谢谢

4

1 回答 1

6

如果使用 FileSystemObject 是可以接受的,您可以使用此处描述的方法。

总结一下:

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
于 2011-06-21T14:45:37.437 回答