I would like to find the name of the file with the most recent creation date in a given folder.
I grabbed this code on this site which takes me a step closer but I am still missing something. How do I get the max date out of that.
Here's the code:
Dim oFSO As Object, oFolder As Object, oFile As Object
Dim sPath As String
sPath = "G:\my path\"
Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FolderExists(sPath) Then
Set oFolder = oFSO.GetFolder(sPath)
For Each oFile In oFolder.Files
If LCase$(Right$(oFile.Name, 4)) = ".xls" Then
Debug.Print oFile.Name, oFile.DateCreated
End If
Next oFile
Set oFolder = Nothing
Else
msgbox "Cannot find " & sPath
End If
Set oFSO = Nothing
Thanks for any help.
Mike
I grabbed this code on this site which takes me a step closer but I am still missing something. How do I get the max date out of that.
Here's the code:
Dim oFSO As Object, oFolder As Object, oFile As Object
Dim sPath As String
sPath = "G:\my path\"
Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FolderExists(sPath) Then
Set oFolder = oFSO.GetFolder(sPath)
For Each oFile In oFolder.Files
If LCase$(Right$(oFile.Name, 4)) = ".xls" Then
Debug.Print oFile.Name, oFile.DateCreated
End If
Next oFile
Set oFolder = Nothing
Else
msgbox "Cannot find " & sPath
End If
Set oFSO = Nothing
Thanks for any help.
Mike