Home |
Search |
Today's Posts |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
MS Excel 2007 "Recent" files not updating | Excel Discussion (Misc queries) | |||
Delete emty file names from "recent documents" Excel | Excel Discussion (Misc queries) | |||
Macro to delete Recent Files list (except those "pinned") - Excel | Excel Programming | |||
How do I delete unpinned messages from my recent documenrts list? | Excel Discussion (Misc queries) | |||
How do I delete items out of my "recent documents" list? | Excel Discussion (Misc queries) |