To access the list of recent files in VBA use
Sub test() Dim objAllRecentFiles As Object Set objAllRecentFiles = Application.recentfiles End Sub
I do not believe that there is an alternative way, besides using the registry, to determine if the latest files are attached or not. In the example below, you can view all the latest files, identify those that are not attached, and modify the registry so that they are pinned. Commented removal method
Sub test2() Dim objAllRecentFiles As Object Dim WSHShell, RegKey, rKeyWord Set WSHShell = CreateObject("WScript.Shell") Set objAllRecentFiles = Application.recentfiles RegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Excel\File MRU\" For Each rFile In objAllRecentFiles rKeyWord = WSHShell.RegRead(RegKey & "Item " & rFile.Index) If InStr(1, rKeyWord, "[F00000000]") Then 'Delete registry 'rFile.Delete 'Change registry setting to make recent file pinned strPinned = Replace(rKeyWord, "[F00000000]", "[F00000001]") WSHShell.Regwrite (RegKey & "Item " & rFile.Index), strPinned, "REG_SZ" End If Next rFile End Sub
source share