Share via


How to: List Recently Used Workbook Files

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2003

  • Excel 2007

For more information, see Features Available by Application and Project Type.

The RecentFiles property returns a collection that contains the names of all the files that appear in the Microsoft Office Excel list of recently used files. The length of the list varies depending on the number of files the user has selected to retain. You can display the results in a range.

To list recently used workbooks in a range object

  • Loop through the list of recent files and display the names in cells relative to a Range object.

    Dim rng As Excel.Range = Me.Application.Range("A1")
    
    Dim i As Integer 
    For i = 1 To Me.Application.RecentFiles.Count
        rng.Offset(i - 1, 0).Value2 = Me.Application.RecentFiles(i).Name
    Next
    
    Excel.Range rng = this.Application.get_Range("A1", missing);
    for(int i=1; i<=this.Application.RecentFiles.Count; i+)
     {
        rng.get_Offset(i - 1,0).Value2 = this.Application.RecentFiles.get_Item(i).Name;
      }
    

See Also

Tasks

How to: Display a Dialog Box to Open Excel Files

Concepts

Working with Workbooks

NamedRange Control

The Variable missing and Optional Parameters in Office Solutions