You could also write Admin's function using VB's built in FileDateTime function instead of calling out to the FileSystemObject scripting object (note that I reorganized the code in keeping with my own personal programming preferences)...
Code:Function GetLastModifiedFile(ByVal FolderName As String, Optional FileType As String = "Excel") As String Dim FN As String, FileName As String, FileNamePattern As String Dim NewestFileName As String, MaxDate As Date If Right$(FolderName,1) <> Application.PathSeparator Then FolderName = FolderName & Application.PathSeparator Select Case UCase(FileType) Case "EXCEL": FileNamePattern = "*.xl*" Case "WORD": FileNamePattern = "*.do*" Case "POWERPOINT": FileNamePattern = "*.pp*" End Select FN = Dir$(FolderName & FileNamePattern) Do While FN <> "" If FileDateTime(FolderName & FN) > MaxDate Then MaxDate = FileDateTime(FolderName & FN) NewestFileName = FN End If FN = Dir$ Loop GetLastModifiedFile = NewestFileName End Function




Reply With Quote

Bookmarks