+ Reply to Thread
Results 1 to 12 of 12

Macro to open the most recent file in a folder

  1. #1
    Forum Contributor
    Join Date
    04-20-2020
    Location
    New Jersey, NJ
    MS-Off Ver
    MS Office 365
    Posts
    159

    Macro to open the most recent file in a folder

    Hey there,

    I'm looking for some code that will open the most recent file in a folder.

    Any thoughts?

    Here is the file path for the actual file: M:\Locts\0366\0366avail060220.xlsx

    Thank you in advance.

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Macro to open the most recent file in a folder

    How about...
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hey ! Try this demonstration …


    Close to previous post but as a VBA beginner starter to open the most recent .xlsx file :

    PHP Code: 
    Sub Demo1()
      Const 
    "M:\Locts\0366\"
        Dim F$, D As Date, R As Date, T$
            F = Dir(P & "
    *.xlsx")
      While F > ""
            D = FileDateTime(P & F):  If D > R Then R = D: T = F
            F = Dir
      Wend
            If R Then Workbooks.Open P & T
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » ! ◄ ◄
    Last edited by Marc L; 06-05-2020 at 11:19 AM. Reason: typo …

  4. #4
    Forum Contributor
    Join Date
    04-20-2020
    Location
    New Jersey, NJ
    MS-Off Ver
    MS Office 365
    Posts
    159

    Re: Macro to open the most recent file in a folder

    Thank you for responding, but this only gives me the date and time it was saved.

  5. #5
    Forum Contributor
    Join Date
    04-20-2020
    Location
    New Jersey, NJ
    MS-Off Ver
    MS Office 365
    Posts
    159

    Re: Hey ! Try this demonstration …

    Works perfectly. Thank you!

  6. #6
    Forum Contributor
    Join Date
    04-20-2020
    Location
    New Jersey, NJ
    MS-Off Ver
    MS Office 365
    Posts
    159

    Re: Hey ! Try this demonstration …

    Any way to set the "M:\Locts\0366\" as a variable number?

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Macro to open the most recent file in a folder


    So it can't be a constant like in my demonstration but a String variable as Dangelor used in his code …

  8. #8
    Forum Contributor
    Join Date
    04-20-2020
    Location
    New Jersey, NJ
    MS-Off Ver
    MS Office 365
    Posts
    159

    Re: Macro to open the most recent file in a folder

    His code only opens a msg box that says when the file was last saved or something

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro to open the most recent file in a folder


    I just pointed out the way dangelor used for the path - a String variable - as you can easily see in his code …

  10. #10
    Forum Contributor
    Join Date
    04-20-2020
    Location
    New Jersey, NJ
    MS-Off Ver
    MS Office 365
    Posts
    159

    Re: Macro to open the most recent file in a folder

    Hey man. I know I'm an idiot you don't gotta rub it in

    Thank you.

    Working on saving the open workbook as a different name now if the same name exists. Any thoughts, Master Marc?
    Last edited by jack.a; 06-05-2020 at 02:37 PM.

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Macro to open the most recent file in a folder


    You asked for opening the most recent workbook.
    So you want to save it with a different name - which I can't guess - but if this different name already exists
    then you want to save it with another different name - which I can't guess neither - or ?

  12. #12
    Forum Contributor
    Join Date
    04-20-2020
    Location
    New Jersey, NJ
    MS-Off Ver
    MS Office 365
    Posts
    159

    Re: Macro to open the most recent file in a folder

    Thanks Marc - figured it all out in the end. Here is my code in it's entirety.


    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to open the more recent file in specific folder
    By mgnab in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-23-2019, 07:02 AM
  2. Open Second most recent file in folder
    By Stratty in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2017, 10:40 AM
  3. Macro to open Most Recent PDF file from folder
    By conchhouse in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-21-2016, 10:59 AM
  4. [SOLVED] vba to open recent dated file in a folder
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-10-2014, 08:47 AM
  5. Open a file in the most recent folder
    By primaldeity in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-27-2013, 07:34 PM
  6. How to open the most recent file in a folder
    By Mr. Structure in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-30-2010, 09:42 AM
  7. How to Open Most Recent File in a Folder
    By 1100shadowman in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-16-2009, 08:30 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1