Hi
Try
and call the function likeCode:Function GetLastModifiedFile(ByVal FolderName As String, Optional FileType As String = "Excel") As String Dim objFso As Object Dim Fldr As Object Dim f, FileName As String Dim d As Single Dim t As Single, e As String Set objFso = CreateObject("Scripting.FileSystemObject") If Right$(FolderName, 1) <> Application.PathSeparator Then FolderName = FolderName & Application.PathSeparator Set Fldr = objFso.getfolder(FolderName) d = 0 For Each f In Fldr.Files FileName = f.Name e = Mid$(FileName, InStrRev(FileName, ".") + 1) Select Case UCase$(FileType) Case "EXCEL" If e Like "xl*" Then t = f.datelastmodified If t > d Then d = t: GetLastModifiedFile = FileName End If End If Case "WORD" If e Like "do*" Then t = f.datelastmodified If t > d Then d = t: GetLastModifiedFile = FileName End If End If Case "POWERPOINT" If e Like "pp*" Then t = f.datelastmodified If t > d Then d = t: GetLastModifiedFile = FileName End If End If End Select Next End Function
Code:Sub kTest() MsgBox GetLastModifiedFile("YourFolder") End Sub




Reply With Quote

Bookmarks