How to delete recent document history in Excel ribbon using VBA

How to delete recent document history in Excel ribbon using VBA.

I use the code below, but it does not work.

Sub Button1_Click()
    For i = 1 To Application.RecentFiles.Count - 1
        Application.RecentFiles(i).Delete
    Next i
End Sub

Thank...

+3
source share
3 answers

To clear the list of recently used files and not spoil the user settings, the following code will work:

originalSetting = Application.RecentFiles.Maximum

Application.RecentFiles.Maximum = 0

Application.RecentFiles.Maximum = originalSetting

This will delete the latest files, and then reset the maximum number of recent files back to their original state.

If you just want to delete them separately, you can execute them in reverse order to complete the task.

 Dim i As Integer

For i = Application.RecentFiles.Count To 1 Step -1
    Application.RecentFiles.Item(i).Delete
Next

, RecentFiles, . , .

, Base 1 Base 0, - Application.RecentFiles.Count, .RecentFiles.Count-1.

Excel..:)

+3

To clear the reference book from the list of recent files, use this:

Sub DeleteFileFromRecentFiles()
    Dim i As Integer
    For Each RecentFile In Application.RecentFiles
        If ActiveWorkbook.Name = RecentFile.Name Then
            i = i + 1
            Application.RecentFiles.Item(i).Delete
        End If
    Next
End Sub

Regards, Richard

0
source

Source: https://habr.com/ru/post/1729568/


All Articles