L
LeeL
Hello,
Jacob Skaria recently provided the very helpful function pasted below. I
have a follow-up question, can the function also include a way to get other
attributes such as: Datecreated, DateLastModified, and DateLastAccessed?
Sub Macro()
MsgBox GetLatestFileName("c:\test")
MsgBox GetLatestFileName("c:\test", "ba*.txt")
End Sub
Function GetLatestFileName(strFolder As String, Optional strFilter As String)
Dim strFile As String, varDT As Variant
strFile = Dir(strFolder & "\" & strFilter, vbNormal)
Do While strFile <> ""
If FileDateTime(strFolder & "\" & strFile) > varDT Then
varDT = FileDateTime(strFolder & "\" & strFile)
GetLatestFileName = strFile
End If
strFile = Dir
Loop
End Function
Jacob Skaria recently provided the very helpful function pasted below. I
have a follow-up question, can the function also include a way to get other
attributes such as: Datecreated, DateLastModified, and DateLastAccessed?
Sub Macro()
MsgBox GetLatestFileName("c:\test")
MsgBox GetLatestFileName("c:\test", "ba*.txt")
End Sub
Function GetLatestFileName(strFolder As String, Optional strFilter As String)
Dim strFile As String, varDT As Variant
strFile = Dir(strFolder & "\" & strFilter, vbNormal)
Do While strFile <> ""
If FileDateTime(strFolder & "\" & strFile) > varDT Then
varDT = FileDateTime(strFolder & "\" & strFile)
GetLatestFileName = strFile
End If
strFile = Dir
Loop
End Function