Mike H,
"The error happens because deleting items 'on the fly' messes up the
index so if you build an array of file indices to delete the problem
goes away." and seeing your two loops.
Doesn't the error occur not just because the items are being deleted,
but because they're being deleted AND we're moving down the list, so
that every time we delete something, the items with larger index numbers
(items below the deleted item) get re-indexed?
If we were to run UP the list, deleting 'on-the-fly', any deletions
would only re-index those items that have already been processed. That
way, we wouldn't need to have two loops any more, nor create an array of
items to delete. Something on the lines of:
For X = Application.RecentFiles.Count to 1 step -1
'query and delete item if necessary
Next X
..time passes..
actually I've had a go at coding it, but haven't tested the following:
Sub ClearMRU_NotPinned3()
Dim WSHShell, RegKey, rKeyWord
Set WSHShell = CreateObject("WScript.Shell")
'On Error Resume Next 'I hope this isn't necessary
OriginalMax = Application.RecentFiles.Maximum
Application.RecentFiles.Maximum = 50
RegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\ Excel\File
MRU\"
For X = Application.RecentFiles.Count To 1 Step -1
rKeyWord = WSHShell.RegRead(RegKey & "Item " &
Application.RecentFiles(X).Index)
If InStr(1, rKeyWord, "[F00000000]") Then
Application.RecentFiles(X).Delete
Next X
Application.RecentFiles.Maximum = OriginalMax
End Sub
Geoff,
I'm sure you'll have something that's workable even if it has been
worked to death!
--
p45cal
*p45cal*
------------------------------------------------------------------------
p45cal's Profile:
http://www.thecodecage.com/forumz/member.php?userid=558
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=147510