Notifications
Clear all
Topic starter
Can anyone help me with the code for last modified file in the folder?
Posted : 23/02/2022 8:56 am
We need more information to help you. What problems are you having?
Posted : 23/02/2022 11:19 am
If you want to open last modified file in the folder, try below code
Sub openLastModified()
Dim FolderPath As String, tableName As String, latestTblName As String
Dim latestModified As Date, modifiedDate As Date
FolderPath = "path to your folder"
tableName = Dir(FolderPath & "*.xlsx")
'or use below line for any type of file
'tableName = Dir(FolderPath & "*")
Do While tableName <> vbNullString
modifiedDate = FileDateTime(FolderPath & tableName)
If latestModified < modifiedDate Then
latestModified = modifiedDate
latestTblName = tableName
End If
tableName = Dir()
Loop
Workbooks.Open FolderPath & latestTblName
Posted : 13/03/2022 7:53 pm