Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Add open file to last files opened on Menu

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Add open file to last files opened on Menu


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"
wrote in message
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Add open file to last files opened on Menu

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" wrote in message
...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Form when file opened Dana Excel Discussion (Misc queries) 2 July 25th 08 04:36 PM
Can't open a file I just opened the day before. DJ Excel Discussion (Misc queries) 0 October 28th 07 11:41 PM
cannot open the excel file, the file is already opened cannot open the excel document Excel Discussion (Misc queries) 1 May 19th 06 07:45 AM
Bug when macro tries to open allready opened file Snoopy[_2_] Excel Programming 3 April 7th 06 01:12 PM
How set file open path to filepath of file opened with Explorer ? RandyDtg1 Excel Programming 0 May 14th 04 02:05 AM


All times are GMT +1. The time now is 01:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"