Class RecentFile (Excel VBA)

The class RecentFile represents a file in the list of recently used files.

Item

To use a RecentFile class variable it first needs to be instantiated, for example

Dim rcnfl as RecentFile
Set rcnfl = Application.RecentFiles(Index:=1)

The following procedures can be used to set variables of type RecentFile: RecentFiles.Add and RecentFiles.Item.

For Each

Here is an example of processing the RecentFile items in a collection.

Dim rcnfl As RecentFile
For Each rcnfl In Application.RecentFiles
	
Next rcnfl

Delete

Deletes the object.

Application.RecentFiles(1).Delete

Index

Returns a Long value that represents the index number of the object within the collection of similar objects.

Dim lngIndex As Long
lngIndex = Application.RecentFiles(1).Index

Name

Returns a String value that represents the name of the object.

Dim strName As String
strName = Application.RecentFiles(1).Name

Open

Opens a recent workbook.

Dim wb As Workbook
Set wb = Application.RecentFiles(1).Open

Path

Returns a String value that represents the complete path to the workbook or file that this RecentFile object represents.

Dim strPath As String
strPath = Application.RecentFiles(1).Path

RecentFiles.Add

Adds a file to the list of recently used files.

Add (Name)

Name: The file name.

Application.RecentFiles.Add Name:="Oscar.xls"

RecentFiles.Count

Returns a Long value that represents the number of objects in the collection.

Dim lngCount As Long
lngCount = Application.RecentFiles.Count

RecentFiles.Item

Returns a single object from a collection.

Item (Index)

Index: The index number of the object.

Dim rcnflItem As RecentFile
Set rcnflItem = Application.RecentFiles(Index:=1)

RecentFiles.Maximum

Returns or sets the maximum number of files in the list of recently used files. Can be a value from 0 (zero) through 50.

Application.RecentFiles.Maximum = 8