How to open recent files from list?

A

avkokin

Hello. Thank's all for your answers. But I unknow how to open the
files from list which I create into my item menu.
This is the code with help it I created new item menu into menu bar
with the list of recent files. Now how to open they?

Sub newItemMenuBar()
'create new item menu "MRUF" into menu bar
Dim rf As RecentFile
Dim oPopup As CommandBarPopup
Dim oBtn As CommandBarButton
Dim i As Long

On Error Resume Next
Set oPopup = CommandBars.FindControl(Tag:="rf")
If Not oPopup Is Nothing Then
oPopup.Delete
End If
Set oPopup =
CommandBars.ActiveMenuBar.Controls.Add(Type:=msoControlPopup,
Before:=1)
With oPopup
.Caption = "MRUF"
.BeginGroup = True
.Tag = "rf"
End With

If RecentFiles.Count >= 1 Then
For Each rf In RecentFiles
If Len(Dir(rf.Path & "\" & rf.Name)) = 0 Then
RecentFiles(rf.Index).Delete
End If
Next rf
Set rf = Nothing
For i = 1 To RecentFiles.Count
Set oBtn = oPopup.Controls.Add(msoControlButton)
With oBtn
.Caption = Application.RecentFiles(i).Name
.Style = msoButtonCaption
.OnAction = "openRF"
End With
Next i
End If

Set oPopup = Nothing
Set oBtn = Nothing
End Sub

Sub openRF()
????
End Sub

Thank you very much.
 
G

Greg Maxey

Add the .Tag line in your With oBtn code:

With oBtn
.Caption = Application.RecentFiles(i).Name
.Style = msoButtonCaption
.Tag = Application.RecentFiles(i).Path & "\" &
Application.RecentFiles(i).Name
.OnAction = "openRF"
End With

Then:

Sub openRF()
Documents.Open CommandBars.ActionControl.Tag
End Sub
 

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