Restoring the Recently Used File List

G

Guest

Good morning, all,

One of my applications disables the recently used file list, but when I
re-enable it, all its entries are lost.

Is there any way in which I can store the filenames in the list to an array,
then restore them later on?

Thanks in advance

Pete
 
G

Guest

Peter:

Other method,delete ThisWorkbook.FullName in RecentFiles list

With ThisWorkbook
For Ndx = 1 To Application.RecentFiles.Count
If Application.RecentFiles(Ndx).Path = .FullName Then
Application.RecentFiles(Ndx).Delete
Exit For
End If
Next Ndx
End With
 
G

Guest

Good morning, ChiJanZen

Well, at least I understand the object collection that I need to refer to,
but I can't get it to work at the moment.

Even

MsgBox (Application.RecentFiles(1))

doesn't display an empty message box.

I'm stumped.

Pete


doesn't display anything - not even the messagebox
 
G

Guest

Peter:
doesn't display an empty message box.


MsgBox (Application.RecentFiles(1).Path)


or

Dim Recent As Variant

Sub test()
ReDim Recent(Application.RecentFiles.Count)
For Each f In Application.RecentFiles
Recent(I) = f.Path
I = I + 1
Next
' Application.RecentFiles.Maximum = 0
For I = 0 To UBound(Recent)
MsgBox Recent(I)
Next I
End Sub
 
G

Guest

ChiJanZen,

I'm quite a bit further on now, thanks to your help!

I have now successfully stored the items in the recently used file list to a
variable, and I can reference the array elements individually. What I now
want to do is first of all display them in a for each loop, then work towards
restoring them back from the array to the recently used file list once more.

However, I'm having some trouble doing this. Here's what I have:

Sub A0_RecentlyUsedFileListStore()
ReDim RecentFileListArray(Application.RecentFiles.Count - 1) 'As Variant
On Error Resume Next
MsgBox (Application.RecentFiles.Count & " file(s) in Recently Used File
List")
For NDX = 1 To Application.RecentFiles.Count
MsgBox (Application.RecentFiles(NDX).Name)
RecentFileListArray(NDX) = Application.RecentFiles(NDX).Name
Next
MsgBox (LBound(RecentFileListArray) & " " & UBound(RecentFileListArray))
End Sub

When I run my display macro, I get a "Subscript out of range" error.

Sub A0_RecentlyUsedFileListDisplay()
Dim Counter As Integer
For Counter = LBound(RecentFileListArray) To UBound(RecentFileListArray)
MsgBox (RecentFileListArray(Counter))
Next
End Sub


Any ideas what I'm doing wrong now, please?

Thanks in advance

Pete
 
G

Guest

Peter:

try,

Dim RecentFileListArray As Variant
Option Base 1
Sub A0_RecentlyUsedFileListStore()
ReDim RecentFileListArray(Application.RecentFiles.Count) 'As Variant
On Error Resume Next
MsgBox (Application.RecentFiles.Count & " file(s) in Recently Used File
List ")
For NDX = 1 To Application.RecentFiles.Count
MsgBox (Application.RecentFiles(NDX).Name)
RecentFileListArray(NDX) = Application.RecentFiles(NDX).Name
Next
MsgBox (LBound(RecentFileListArray) & " " & UBound(RecentFileListArray))
End Sub

Sub A0_RecentlyUsedFileListDisplay()
Dim Counter As Integer
For Counter = LBound(RecentFileListArray) To UBound(RecentFileListArray)
MsgBox (RecentFileListArray(Counter))
Next
End Sub
 
G

Guest

Good morning, ChiZanZen!

This works fine - all I now need to do is figure out how to get the values
stored in the array back into the Recently used file list - I'm not sure if
this is even possible, though.

I've used:

Sub RecentlyUsedFileListRestore()
On Error Resume Next

For NDX = LBound(RFLArray) To UBound(RFLArray)
Application.RecentFiles(NDX) = RFLArray(NDX)
Next NDX
Application.DisplayRecentFiles = True
End Sub

but it doesn't appear to work. I'm not sure if the use of
application.displayrecentfiles = true is affecting it and re-resetting the
list.

Anyway, thanks for your help and I'll persevere, though once again, any
thoughts would be greatly appreciated!

Regards

Pete

P.S. it's 09:26 here at the moment - what time is it where you are? I don't
want to keep you from your bed! :)
 
G

Guest

Norman,

Spot on! Thank you VERY much, and if I don't get to bend your ear again this
year, have a great Christmas! :)

Regards

Pete
 
G

Guest

Peter:

it's 17:58 here

first Run A0_RecentlyUsedFileListStore
and Run RecentlyUsedFileListRestore

Dim RecentFileListArray As Variant
Dim num As Integer
Option Base 1
Sub A0_RecentlyUsedFileListStore()
ReDim RecentFileListArray(Application.RecentFiles.Count) 'As Variant
On Error Resume Next
For NDX = 1 To Application.RecentFiles.Count
RecentFileListArray(NDX) = Application.RecentFiles(NDX).Name
Next
'del RecentFiles
num = Application.RecentFiles.Maximum
Application.RecentFiles.Maximum = 0
End Sub

Sub RecentlyUsedFileListRestore()
Application.RecentFiles.Maximum = num
For NDX = LBound(RecentFileListArray) To UBound(RecentFileListArray)
Application.RecentFiles.Add Name:=RecentFileListArray(NDX)
Next NDX
End Sub
 
G

Guest

Hi, ChiJanZen!

Yep, it was the recentfiles.add bit that worked it.

Thanks VERY much for your help. I have a 14:00 meeting at which I needed to
be able to demonstrate this and now I can! :)))))

Thanks for your help on this and recently - I wish you and your family a
good Christmas and New Year.

Regards

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top