4

VBAを使用してExcel 2010でこれを行う方法を探しています。

Application.FileSearch メソッドを使用して Excel 2003 で可能でしたが、これは廃止されました。(下記参照)

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 に答える