XL: Macro to Open the Most Recently Used FileLast reviewed: September 2, 1997Article ID: Q109113 |
The information in this article applies to:
SUMMARYIn Microsoft Excel, you can access a list of the four most recently used files by selecting the File menu. The following macro opens the first file and displays the name of the third file in the list.
MORE INFORMATIONMicrosoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose. Note that a line that is preceded by an apostrophe introduces a comment in the code--comments are provided to explain what the code is doing at a particular point in the procedure. The following macro will open the most recently used file. Before you run this macro you must make sure that the most recently used file list is turned on. To verify that this option is selected, choose Options from the Tools menu and then select the General tab. Make sure that the Recently Used File List box is checked.
Option Explicit
Sub MostRecentlyUsedFileList() 'Dimension the array to hold the file listDim files(4) Dim arraypos, begin As Integer Dim item As String
'Initialize a pointer for the arrayarraypos = 0
'Find the position of the File List menuitem. This will be used as a 'starting location in the list of menuitems on the File menu.begin = MenuBars("Worksheet").Menus("file").MenuItems("file list").Index
'Begin loop that continues until it encounters the divider line that 'follows the end of the file listDo Until MenuBars("Worksheet").Menus("file").MenuItems(begin).Caption = "-"
'Place the name of the menuitem into the variable called Item. 'This name will include the ampersand, the number of the file in 'the list, a space, then the file name itself. item = MenuBars("Worksheet").Menus("file").MenuItems(begin).Caption 'Remove the first three characters of Item and place name in array files(arraypos) = Mid(item, 4, Len(item) - 3) 'Increment counter for menuitem and pointer in array begin = begin + 1 arraypos = arraypos + 1Loop
'opens the first file on the most recently used list Workbooks.Open filename:=files(0) 'displays the name of the third file on the most recently used list MsgBox files(2) End Sub |
Additional query words: 7.00 5.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |