VBA example - Excel 2007: list recent used files

VBA code to list recent used files

This VBA code example you will learn how to write VBA code in Excel to display recent files that are open in Excel. The recent files are displayed in recent documents list of Excel Application when you click on the Office Button of Excel. In this VBA code example, we also show you how to set the maximum number of recent files to display in the recent documents list.

To run this example VBA code, you will need a Form, a CommandButton, and a ComboBox.

VBA for Excel: VBA loop to all recent files used.

VBA code for this example:

Option Explicit
Private Sub CommandButton1_Click()

    Dim i As Integer

    i = 1

    'Display the recently opened files

    For i = 1 To Application.RecentFiles.Count

        Cells(i, 1) = Application.RecentFiles(i).Name


    'Set the maximum number of recent files to display

    Application.RecentFiles.Maximum = 10

End Sub


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.