Pinned documents simply remain in the lost rather than drop off at the
bottom. They are not sorted. There is no built-in function to move the
pinned items to the top of the list but it can be done using a macro to read
and write the revised registry entries. The problem with that is that Word
must be closed and re-opened to read the registry changes. The following
macro will do all that, but re-opening Word will have to be done manually,
if the macro is run from Word, as the macro stops when Word is closed.
Ensure that you save the normal template with the macro *before* running it,
or the normal template will become the new first item in the list, whether
or not it is pinned.
The macro first closes any open documents (giving the opportunity to save)
reads the registry entries associated with the recent file list and writes
them to a temporary document before deleting them from the list. That
document is sorted to put the pinned items first. The registry entries are
then re-written in the new order, the temporary document is closed and Word
is closed. When Word is re-opened the recent file list reflects the new
order from the registry.
Sub SortRecentFileList()
Dim oDoc As Document
Dim rNewKey As Range
Dim rFile As RecentFile
Dim i As Long
Dim WSHShell, RegKey, rKeyWord
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
Set oDoc = Documents.Add
Set WSHShell = CreateObject("WScript.Shell")
RegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\File MRU\"
For Each rFile In RecentFiles
rKeyWord = WSHShell.RegRead(RegKey & "Item " & rFile.Index)
oDoc.Range.InsertAfter rKeyWord & vbCr
rFile.Delete
Next rFile
With oDoc
.Paragraphs.Last.Range.Delete
.Range.Sort ExcludeHeader:=False, _
FieldNumber:="Paragraphs", _
SortFieldType:=wdSortFieldAlphanumeric, _
SortOrder:=wdSortOrderDescending
For i = 1 To .Paragraphs.Count
Set rNewKey = .Paragraphs(i).Range
rNewKey.End = rNewKey.End - 1
WSHShell.RegWrite RegKey & "Item " & i, rNewKey.Text
Next i
.Close wdDoNotSaveChanges
End With
Application.Quit
End Sub
You might find it more useful to simply delete the unpinned items from the
list. The following macro does that and does not require Word to be
restarted:
Sub ClearUnpinned()
'Clear recent file list leaving the pinned items
Dim rFile As RecentFile
Dim WSHShell, RegKey, rKeyWord
Set WSHShell = CreateObject("WScript.Shell")
RegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\File MRU\"
For Each rFile In RecentFiles
rKeyWord = WSHShell.RegRead(RegKey & "Item " & rFile.Index)
Select Case Mid(rKeyWord, 10, 1)
Case Is = 0, 2
rFile.Delete
End Select
Next rFile
MsgBox "Recent file list is cleared," & vbCr & _
"retaining the pinned items", _
vbInformation, _
"Clear Recent File List"
End Sub
See also
http://www.gmayor.com/clear_recently_used_file_list.htm
If you want to selectively delete, then it gets altogether more complicated,
but friend and fellow MVP Greg Maxey has done all the work - see
http://gregmaxey.mvps.org/Recent_Files_List_Editor.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>