Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Not in KC anymore
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Open most recent spreadsheet (XP)

    Is there a way to set up a macro that will open up the most recent file, regardless of the name?

    For example, I would like to open the most recent spreadsheet in C:Temp without having to use the Open Dialog box.

    Thanks!

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open most recent spreadsheet (XP)

    Do you mean the first file in Excel's Most Recently Used file list, or the file in a particular directory with the latest file modified date? If the second, do you want to restrict the files to only those with a .xls file extension?
    Legare Coleman

  3. #3
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Not in KC anymore
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open most recent spreadsheet (XP)

    This would be to a file in a particular directory.

    There are only .xls files in that directory.

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open most recent spreadsheet (XP)

    Try this:

    <pre>Public Sub OpenMostRecent()
    Dim strFName As Variant, strRecentFN As String
    Dim datRecent As Date, datThisFile As Date
    Dim oWB As Workbook
    strFName = Dir("C:Temp*.xls", vbNormal)
    While strFName <> ""
    datThisFile = FileDateTime("C:Temp" & strFName)
    If datThisFile > datRecent Then
    datRecent = datThisFile
    strRecentFN = strFName
    End If
    strFName = Dir()
    Wend
    Set oWB = Workbooks.Open("C:Temp" & strRecentFN)
    End Sub
    </pre>

    Legare Coleman

  5. #5
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Not in KC anymore
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open most recent spreadsheet (XP)

    Works great.

    Thanks a bunch.

    <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •