Class RecentFile (Word VBA)

The class RecentFile represents a recently used file. The RecentFile object is a member of the RecentFiles collection.

The main procedures of class RecentFile are Delete, Open and RecentFiles.Add


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

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

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

For Each

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

Dim rcnfl As RecentFile
For Each rcnfl In RecentFiles
Next rcnfl


These are the main methods of the RecentFile class

Delete - Deletes the specified file on the list of recent files.


Open - Opens the specified object. Returns a Document object representing the opened document.

Dim doc As Document
Set doc = RecentFiles(1).Open()

RecentFiles.Add - Returns a RecentFile object that represents a file added to the list of recently used files.

Dim rcnfl As RecentFile
Set rcnfl = RecentFiles.Add(Document:=)


Index returns a Long that represents the position of an item in a collection.

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

Name returns the name of the specified object.

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

Parent returns an object that represents the parent object of the specified RecentFile object.

Dim objParent As Object
Set objParent = RecentFiles(1).Parent

Path returns the disk or Web path to the specified object.

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

ReadOnly true if changes to the document cannot be saved to the original document.

RecentFiles(1).ReadOnly = True

RecentFiles.Count returns a Long that represents the number of recent files in the collection.

Dim lngCount As Long
lngCount = RecentFiles.Count

RecentFiles.Maximum returns or sets the maximum number of recently used files that can appear on the File menu. Can be a number from 0 (zero) through 9.

RecentFiles.Maximum =

RecentFiles.Parent returns an object that represents the parent object of the specified RecentFiles object.

Dim objParent As Object
Set objParent = RecentFiles.Parent