Recent File List Editor

Home Up Odds & Ends Photo Gallery Search Contact Me

 

 

The information in this website is provided without risk or obligation and free of charge.  However, if you have benefitted from my efforts here and would like to make a contribution to help me continue and maintain this work then any donation will be greatly appreciated. Please click the adjacent button to access PayPal.  Thank you.
 

Microsoft Word does not offer a simple and direct method for clearing (removing) files from the "Recently Used File" list that is located at the bottom of the File menu.  In fellow MVP Graham Mayor's webpage Clear Recently Used Files, Graham describes the user interface that is available in Word Options, a VBA solution for sweeping all files from the list, and he shows you how to use the "Destructive Cursor" for removing individual files from the list.  

I was inspired to post this solution after reviewing a proposed method by the budding VBA enthusiast  Patricia Shannon.   Patricia's method got me to thinking about creating a UserForm for this task.  This tips page is a result of those thoughts.

While I am not providing step by step procedures to create the Userform here, my tips page Custom VBA Message Box provides ample information and examples to enable you to duplicate this Userform.

The Userform is shown below.  It provides a multi-select list box in which you can select one or more files using your mouse and command buttons to excute your chosen actions.  Use the form to delete all of the listed files or specific files that you have selected.  It also provides an interface for changing the maximum number of files displayed in the Recently Used File list. 

Remember, "nothing" is deleted from your disk or file folders.  Only the "Recently Used File" list is effected.

The Userform and calling macro code is as follows:

  Option Explicit

'Call macro code located in a project module
Sub CallRecentFiles()
Dim RecentFiles As UF
Set RecentFiles = New UF
RecentFiles.Show
Unload RecentFiles
Set RecentFiles = Nothing
End Sub

 
  Option Explicit

Private Sub cmdCancel_Click()
Me.Hide
End Sub

Private Sub cmdDeleteAll_Click()
Dim i As Long
Do While Application.RecentFiles.Count > 0
    i = Application.RecentFiles.Count
    Application.RecentFiles(i).Delete
Loop
Me.Hide
End Sub

Private Sub cmdDeleteSel_Click()
Dim i As Long
For i = Application.RecentFiles.Count To 1 Step -1
    If Me.ListBox1.Selected(i - 1) = True Then
        Application.RecentFiles(i).Delete
    End If
Next
Me.Hide
End Sub

Private Sub cmdSetClose_Click()
If Me.cmdSetClose.Caption = "Set" Then
    Application.RecentFiles.Maximum = Me.NumFiles.Text
    Me.cmdSetClose.Caption = "Close"
Else
    Me.Hide
End If
End Sub

Private Sub NumFiles_Change()
If Val(NumFiles.Text) > 50 Then
    NumFiles.Text = 50
ElseIf Val(NumFiles.Text) < 0 Then
    NumFiles.Text = 0
End If
End Sub

Private Sub NumFiles_Enter()
If Me.cmdSetClose.Caption = "Close" Then
    Me.cmdSetClose.Caption = "Set"
End If
End Sub

Private Sub SpinButton1_SpinDown()
If Me.cmdSetClose.Caption = "Close" Then
    Me.cmdSetClose.Caption = "Set"
End If
If Val(NumFiles.Text) = 0 Then
    NumFiles.Text = 50
Else
    NumFiles.Text = Val(NumFiles.Text - 1)
End If
End Sub

Private Sub SpinButton1_SpinUp()
If Me.cmdSetClose.Caption = "Close" Then
    Me.cmdSetClose.Caption = "Set"
End If
If Val(NumFiles.Text) > 49 Then
    NumFiles.Text = 0
Else
    NumFiles.Text = Val(NumFiles.Text + 1)
End If
End Sub

Private Sub UserForm_Initialize()
Dim oRF As RecentFile
Dim oTrucPath As String
For Each oRF In Application.RecentFiles
    If Len(oRF.Path) < 60 Then
        Me.ListBox1.AddItem oRF.Path & "\" & oRF.Name
    Else
        oTrucPath = Left(oRF.Path, 12) & "\...\" & oRF.Name
        Me.ListBox1.AddItem oTrucPath
    End If
Next
Me.ListBox1.MultiSelect = fmMultiSelectMulti
NumFiles.Text = Application.RecentFiles.Maximum
Me.cmdSetClose.Caption = "Set"
End Sub

 
I saved the calling macro and Userform in a template AddIn located in my Word Startup directory.  This way the Recently Used File Editor is available automatically when Word starts.  I call the macro with a menu command on my File menu:

Or in Word2007 the template adds the macro command to the Add-In ribbon.

For help assigning a macro to a menu (including mouse right button shortcut menu) or toolbar button, see How to assign a Word command or macro to a toolbar or menu

You can also download a template here:  Recently Used Files Editor.   Then unzip the file to your Word Templates directory and load it using Tools>Templates and Add-Ins or in your Word Startup directory so it loads automatically when Word starts.  For more on Add-Ins and how to load them, see the heading "Organizing Global Templates" at:    Organizing Your Macros


Looking for something else?

Google