Forum

Open last modified ...
 
Notifications
Clear all

Open last modified file

3 Posts
3 Users
0 Reactions
371 Views
(@just-started-vba)
Posts: 1
New Member
Topic starter
 

Can anyone help me with the code for last modified file in the folder?

 
Posted : 23/02/2022 8:56 am
(@jstewart)
Posts: 216
Estimable Member
 

We need more information to help you. What problems are you having?

 
Posted : 23/02/2022 11:19 am
 A S
(@ac-porta-via)
Posts: 6
Active Member
 

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
Share: