The other day i found a snippet of code that has helped me locate the latest version of all files in a particular folder. How do i amend this code so that the file that is ultimately opened is the one that has been created latest, irrespective of when files have been modified.
https://www.mrexcel.com/forum/excel-questions/1111630-workbook-close-not-working.html
https://www.mrexcel.com/forum/excel-questions/1111630-workbook-close-not-working.html
Code:
Option Explicit
Sub reportpackage()
Dim MyPath As String
Dim MyFile As String
Dim LatestFile As String
Dim LatestDate As Date
Dim LMD As Date
Dim MLPwkb As String, SourceWb As Workbook
Set SourceWb = ThisWorkbook
MyPath = \\FPMB1FNP02\Groups$\Internal_Management_Reports\DailyMLP
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
MyFile = Dir(MyPath & "*.xls", vbNormal)
If Len(MyFile) = 0 Then
MsgBox "No files were found...", vbExclamation
Exit Sub
End If
Do While Len(MyFile) > 0
LMD = FileDateTime(MyPath & MyFile)
If LMD > LatestDate Then
LatestFile = MyFile
LatestDate = LMD
End If
MyFile = Dir
Loop
MLPwkb = MyPath & LatestFile
With Workbooks.Open(LatestFile)