Can anyone help me with the code for last modified file in the folder?
Opening last modified file
- Just started VBA
- Thread is marked as Resolved.
-
-
-
Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the URL from the address bar in your browser) to the cross-post. We are here to help so help us help you!
Read this to understand why we ask you to do this
-
-
-
Code
Display MoreOption Explicit Sub lastModifiedFileInFolder() Dim fldr$, fn$, lastModifiedFile$, dt As Date With Application.FileDialog(msoFileDialogFolderPicker) If .Show = -1 Then fldr = .SelectedItems(1) End With If fldr <> "" Then fn = Dir(fldr & "\*.xls*") While fn <> "" If dt = 0 Or FileDateTime(fldr & "\" & fn) > dt Then dt = FileDateTime(fldr & "\" & fn) lastModifiedFile = fn End If fn = Dir Wend End If If lastModifiedFile <> "" Then If MsgBox("Open last modified file?:" & vbLf & vbLf & lastModifiedFile & vbLf & vbLf & "Modified: " & dt, 68) = vbYes Then Workbooks.Open fldr & "\" & lastModifiedFile End If End If End Sub
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!