Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Add open file to last files opened on Menu

6 views
Skip to first unread message

Steven

unread,
May 6, 2006, 7:56:01 PM5/6/06
to
I am opening files from within an excel workbook:

Note: vOPen and vPassword are hard coded in the workbook and I save the
cell values to the variables and then on before double click I do this to
open the selected file:

Workbooks.Open Filename:=vOpen, Password:=vPassword, UpdateLinks:=3

The issue is the opened file is not added to the most recent opened under
Files on the Menu. Is there code that would add the file to the list?

Thanks for your help.

Steven


Jim Cone

unread,
May 6, 2006, 9:28:36 PM5/6/06
to

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

' Original idea by Dana DeLouis
' Removes non-existent files from the Recent Files List on the File Menu.
' Adds the names of any open & saved workbooks to the list.
' Maximum is nine names.
'-----------------------------------------------------
Sub RecentFilesAddToList()
'Created Jan 09, 2002 - Jim Cone - San Francisco, USA
On Error GoTo FileHandler
Dim NewFiles As Byte
Dim N As Long
Dim FileCount As Long
Dim MsgText As String
Dim AddText As String
Dim ListOfFiles() As String
Dim FileFlag As Boolean
Dim WB As Excel.Workbook

Application.DisplayRecentFiles = True
Application.RecentFiles.Maximum = 9

RecentFilesCleanUp AddText 'Call Sub

With Application.RecentFiles
'Determined after invalid file names are removed in called sub
FileCount = .Count
If FileCount Then
ReDim ListOfFiles(1 To FileCount)
For N = 1 To FileCount
ListOfFiles(N) = .Item(N).Path
Next 'N
End If

For Each WB In Workbooks
If Len(WB.Path) Then
For N = 1 To FileCount
'Compare the text after the last path separator to the workbook name.
If Dir(ListOfFiles(N)) = WB.Name Then
FileFlag = True
Exit For
End If
Next 'N

If Not FileFlag Then
.Add Name:=WB.FullName
MsgText = MsgText & " " & Chr$(34) & WB.Name & Chr$(34) & " " & vbCr
NewFiles = NewFiles + 1
Else
FileFlag = False
End If
End If
'Only nine names allowed in list
If NewFiles > 8 Then
Beep
Exit For
End If
Next 'WB
.Maximum = .Maximum
End With 'Application.RecentFiles
Erase ListOfFiles

If NewFiles = 0 Then
If Len(AddText) Then MsgText = "No workbook file names were added. " _
Else MsgText = "No changes were made to the file list. "
ElseIf NewFiles = 1 Then
'Remove the carriage return
MsgText = "Workbook " & Left$(MsgText, Len(MsgText) - 1) & "was added. "
Else
MsgText = "These workbook names were added: " & vbCr & MsgText
End If

MsgBox MsgText & AddText, vbInformation, " Recent Files List - Refresh"
Set WB = Nothing
Exit Sub

FileHandler:
Beep
Set WB = Nothing
End Sub

'-----------------------------------------------------
'Called by RecentFilesAddToList
'-----------------------------------------------------
Sub RecentFilesCleanUp(ByRef MoreText As String)
'Created Jan 09, 2002 - Jim Cone - San Francisco, USA
Dim N As Long
Dim BadFiles As Byte

For N = Application.RecentFiles.Count To 1 Step -1
With Application.RecentFiles(N)
On Error Resume Next
'Does not work on floppy drive???
If Len(Dir(.Path)) = 0 Then
On Error GoTo 0
.Delete
BadFiles = BadFiles + 1
End If
End With
Next ' N

If BadFiles = 1 Then
MoreText = vbCr & "One invalid file name deleted. "
ElseIf BadFiles > 1 Then
MoreText = vbCr & BadFiles & " invalid file names deleted. "
End If
End Sub
'-----------------------------------------------------

"Steven" <Ste...@discussions.microsoft.com>
wrote in message

Tom Ogilvy

unread,
May 6, 2006, 10:04:51 PM5/6/06
to
Look in excel vba help for the recentfiles collection. It has an add method

Also see the recentfile object.

Also Application.DisplayRecentFiles

--
Regards,
Tom Ogilvy

"Steven" <Ste...@discussions.microsoft.com> wrote in message

news:8E26E5E1-E6BE-450A...@microsoft.com...

0 new messages