[COLOR=#00007F][FONT="]Sub[/FONT][/COLOR][COLOR=#000000][FONT="] OpenLatestFile()[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#007F00][FONT="]'Declare the variables[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]Dim[/FONT][/COLOR][COLOR=#000000][FONT="] MyPath [/FONT][/COLOR][COLOR=#00007F][FONT="]As[/FONT][/COLOR][COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]String[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]Dim[/FONT][/COLOR][COLOR=#000000][FONT="] MyFile [/FONT][/COLOR][COLOR=#00007F][FONT="]As[/FONT][/COLOR][COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]String[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]Dim[/FONT][/COLOR][COLOR=#000000][FONT="] LatestFile [/FONT][/COLOR][COLOR=#00007F][FONT="]As[/FONT][/COLOR][COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]String[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]Dim[/FONT][/COLOR][COLOR=#000000][FONT="] LatestDate [/FONT][/COLOR][COLOR=#00007F][FONT="]As[/FONT][/COLOR][COLOR=#000000][FONT="] Date[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]Dim[/FONT][/COLOR][COLOR=#000000][FONT="] LMD [/FONT][/COLOR][COLOR=#00007F][FONT="]As[/FONT][/COLOR][COLOR=#000000][FONT="] Date[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#007F00][FONT="]'Specify the path to the folder[/FONT][/COLOR]
[COLOR=#000000][FONT="] MyPath = "C:\Users\Domenic\[/FONT][/COLOR][COLOR=#00007F][FONT="]Do[/FONT][/COLOR][COLOR=#000000][FONT="]cuments\"[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#007F00][FONT="]'Make sure that the path ends in a backslash[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]If[/FONT][/COLOR][COLOR=#000000][FONT="] Right(MyPath, 1) <> "\" [/FONT][/COLOR][COLOR=#00007F][FONT="]Then[/FONT][/COLOR][COLOR=#000000][FONT="] MyPath = MyPath & "\"[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#007F00][FONT="]'Get the first Excel file from the folder[/FONT][/COLOR]
[COLOR=#000000][FONT="] MyFile = Dir(MyPath & "*.xls", vbNormal)[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#007F00][FONT="]'If no files were found, exit the sub[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]If[/FONT][/COLOR][COLOR=#000000][FONT="] Len(MyFile) = 0 [/FONT][/COLOR][COLOR=#00007F][FONT="]Then[/FONT][/COLOR]
[COLOR=#000000][FONT="] MsgBox "No files were found...", vbExclamation[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]Exit[/FONT][/COLOR][COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]Sub[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]End[/FONT][/COLOR][COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]If[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#007F00][FONT="]'Loop through each Excel file in the folder[/FONT][/COLOR]
[COLOR=#000000][FONT="] Do [/FONT][/COLOR][COLOR=#00007F][FONT="]While[/FONT][/COLOR][COLOR=#000000][FONT="] Len(MyFile) > 0[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#007F00][FONT="]'Assign the date/time of the current file to a variable[/FONT][/COLOR]
[COLOR=#000000][FONT="] LMD = FileDateTime(MyPath & MyFile)[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#007F00][FONT="]'If the date/time of the current file is greater than the latest[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#007F00][FONT="]'recorded date, assign its filename and date/time to variables[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]If[/FONT][/COLOR][COLOR=#000000][FONT="] LMD > LatestDate [/FONT][/COLOR][COLOR=#00007F][FONT="]Then[/FONT][/COLOR]
[COLOR=#000000][FONT="] LatestFile = MyFile[/FONT][/COLOR]
[COLOR=#000000][FONT="] LatestDate = LMD[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]End[/FONT][/COLOR][COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]If[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#007F00][FONT="]'Get the next Excel file from the folder[/FONT][/COLOR]
[COLOR=#000000][FONT="] MyFile = Dir[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]Loop[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#007F00][FONT="]'Open the latest file[/FONT][/COLOR]
[COLOR=#000000][FONT="] Workbooks.Open MyPath & LatestFile[/FONT][/COLOR]
[COLOR=#000000][FONT="] [/FONT][/COLOR]
[COLOR=#00007F][FONT="]End[/FONT][/COLOR][COLOR=#000000][FONT="] [/FONT][/COLOR][COLOR=#00007F][FONT="]Sub[/FONT][/COLOR]