Sub OpenMostRecentFile()
Dim folderPath As String
Dim fileName As String
Dim fileDate As Date
Dim mostRecentDate As Date
Dim mostRecentFile As String
Dim file As Object
' Set the folder path
folderPath = "C:\test\"
' Initialize variables
mostRecentDate = DateSerial(1900, 1, 1)
' Check each file in the folder
fileName = Dir(folderPath & "*.*")
Do While fileName <> ""
Set file = CreateObject("Scripting.FileSystemObject").GetFile(folderPath & fileName)
fileDate = file.DateCreated
' Check if the file's creation date is more recent
If fileDate > mostRecentDate Then
mostRecentDate = fileDate
mostRecentFile = fileName
End If
fileName = Dir
Loop
' Open the most recent file
If mostRecentFile <> "" Then
Shell "explorer.exe " & folderPath & mostRecentFile, vbNormalFocus
Else
MsgBox "No files found in the folder.",
vbExclamation
End If
End Sub