How to List Recent Files with VBA

How to list recent files with VBA automatically and open the most recent file. This is required when we wish to perform actions like transferring data to the most recent file we have been working on. Watch the video:

Watch this video on YouTube.

Here;s the complete code to open the most recent file auotamically and the some code commented out to list all the recent used files in your worksheet:

Sub displayMostRecentFile()
Range(“A1”) = Application.RecentFiles(1).Name
Workbooks.Open Filename:=Range(“A1”)

‘Application.RecentFiles.Maximum = 5

‘For i = 1 To Application.RecentFiles.Count
‘Cells(i, 1) = Application.RecentFiles(i).Name
End Sub

Further Reading:

Application.RecentFiles property (Excel)

A downloadable sample file for practice: