Set fso = CreateObject("Scripting.FileSystemObject")
Set froot = fso.GetFolder(strstartfldr)
For Each fldr In froot.SubFolders
UserForm1.ComboBox1.AddItem fldr.DateCreated
Next
我可以获取组合框1中的子文件夹列表,但是从这个子文件夹中我如何知道哪个是最后修改的文件夹。
代码
Option Explicit
Function LastFolder(FolderPath As String) As String
Dim fso As Object
Dim froot As Object
Dim fldr As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set froot = fso.GetFolder(FolderPath)
Dim fName As String
Dim fDC As Date
Dim TMP As Date
For Each fldr In froot.subfolders
TMP = fldr.DateCreated
If TMP > fDC Then
fDC = TMP
fName = fldr.Name
End If
Next fldr
LastFolder = fName
End Function
Sub testLastFolder()
Debug.Print LastFolder("F:\StackOverFlow")
End Sub