LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Macro to delete "unpinned" recent files

Yes I agree it's precisely the same as deleting rows on a worksheet, do it
forwards on the fly and you'll potentially miss rows, do it backwards and you
won't.

I ended up with 2 loops because of my confessed lack of understanding of the
registry. I had no idea that it held a record of items not displayed in the
recent files list. I imagined that when you set Excel to display n items then
the registry only held n records with records higher than n being deleted
from the registry.

With the benefit of this new found knowledge I would do it in a single
reverse loop. I didn't bother re-writing the code to do this because as the
OP hasn't responded to the post in 9hrs I guessed interest in it had been
lost.

Mike

"p45cal" wrote:


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

.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Excel 2007 "Recent" files not updating John Gee Excel Discussion (Misc queries) 1 May 28th 10 11:12 PM
Delete emty file names from "recent documents" Excel Touble in Excel Excel Discussion (Misc queries) 2 March 22nd 10 08:10 PM
Macro to delete Recent Files list (except those "pinned") - Excel Geoff Budd Excel Programming 3 October 21st 09 10:45 AM
How do I delete unpinned messages from my recent documenrts list? travelee21 Excel Discussion (Misc queries) 1 August 27th 09 01:54 AM
How do I delete items out of my "recent documents" list? susan carroll Excel Discussion (Misc queries) 2 August 17th 07 06:52 PM


All times are GMT +1. The time now is 03:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"