View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Geoff Budd Geoff Budd is offline
external usenet poster
 
Posts: 10
Default Macro to delete "unpinned" recent files

Hi p45cal
I don't think both Ifs can be true as the first 11 characters of each
registry entry will contain either [F00000000], [F00000001], [F00000002] or
[F00000003]. They can't contain more than one of these strings
simultaneously.
However, your one-line code seems very neat!
Looking at my original code again, it's surprising that the If statements
actually work at all, as the InStr function will return either 1 (if it finds
the string, which will start in position 1) or 0 (if it doesn't find it). As
the If statement is looking for either True (-1) or False (0), it seems
interesting that it executes the delete even though the InStr returns 1.
Perhaps the If statement only checks for False (0)? I think to be absolutely
safe, maybe the If statement should read:
If (InStr(1, rKeyWord, "[F00000000]")=1) Then ...

My original post that dried up was was in the Excel Programming group here
and was entitled:
Macro to delete Recent Files list (except those "pinned") - Excel.
It was dated 10/20/2009

Regards,
Geoff

"p45cal" wrote:


Geoff,
if that works - great.
Being picky-picky, the only thing I'd like to see changed here is this
bit:

If InStr(1, rKeyWord, "[F00000000]") Then
Application.RecentFiles(X).Delete
End If
If InStr(1, rKeyWord, "[F00000002]") Then
Application.RecentFiles(X).Delete
End If

In the unlikely event of both those IFs being true (I know, I know -
very unlikely), then both IFs would try to delete a file - but they'd be
_different__files..

How about combining the above 6 lines into one IF (There's no need for
*End If*s if there's only one action to undertake):

If InStr(rKeyWord, "[F00000000]") or InStr(rKeyWord, "[F00000002]")
Then Application.RecentFiles(X).Delete
(and I've taken out the *1*s from the -Instr- functions -
not needed)

BTW, where did you post before - where the thread 'dried up'?


--
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

.