+ Reply to Thread
Results 1 to 13 of 13

vba to open recent dated file in a folder

  1. #1
    Forum Contributor prabhuduraraj09's Avatar
    Join Date
    05-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    330

    vba to open recent dated file in a folder

    Hi all,

    In a folder i have many files eg., file name "Report for 22.04.2014.xlsm"

    I want vba code to open recent dated file name.

    But i dont want vba code to open with last modified date. because i suspect any of the file could be edited by any user.
    so i want vba code to check with file name and to know which is recent date and open very recent dated file.

    Thank you.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: vba to open recent dated file in a folder

    This will open the most recent dated file name. It tests for file names only within the past 365 days from the current date.

    Change the file folder to suit.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor prabhuduraraj09's Avatar
    Join Date
    05-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    330

    Re: vba to open recent dated file in a folder

    Hi AlphaFrog,

    Thanks for the reply. I could see this could look for recent dates among 365 days.

    For current month i have all april dated files in Folder name "04 Apr 2014"
    like wise for next month folder will be created as "05 May 2014" And users will save all May dated files in there.....

    how could this code could be tweaked to switch over to current month
    but keeping in mind if my code is executed on 1st day of month if there is no file for current date it should switchover to previous month and look for very recent dated file.

    The code which you have suggested would work if all dated files saved in same folder. But i have folders for every month.

    pls help

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: vba to open recent dated file in a folder

    Both the folder names and and the file names are dated; Is that correct?

    The folder names for a given month have a day-date and could be any day in that month? Why not just name the monthly folders something like May 2014 with no day?

    Would you ever have two or more folders for the same month with two different days e.g.; "05 May 2014" and "15 May 2014" ?
    Last edited by AlphaFrog; 04-22-2014 at 09:18 PM.

  5. #5
    Forum Contributor prabhuduraraj09's Avatar
    Join Date
    05-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    330

    Re: vba to open recent dated file in a folder

    Hi AlphaFrog,

    sorry not to make it clear statement.

    The folder name would be in the name of Month - Format is "05 May 2014"
    All files dated from 1st may to 31st may will be in this folder

    And next month folder name created for June month - Format is "06 Jun 2014"
    All files dated from 1st june to 30th june will be in this folder.

    So folder name 05 still says as May and 06 still says June. it is not date.

    hope this clarifies....so how could we tweak your code to embede this

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: vba to open recent dated file in a folder

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor prabhuduraraj09's Avatar
    Join Date
    05-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    330

    Re: vba to open recent dated file in a folder

    Hi AlphaFrog,

    i have tried executing the code, having below folders and file name as example.

    I have two folders

    03 Mar 2014 ( inside this folder there are 2 files Report for 21.04.2014 & Report for 23.04.2014 )
    04 Apr 2014 ( inside this folder there are 2 files Report for 18.03.2014 & Report for 29.03.2014 )

    on trying this code, It browses through current month folder i.e., 04 Apr 2014 and opens recent file i.e, as per example here it opens Report for 23.04.2014

    But if there is no files in 04 Apr 2014 folder of current month.
    Then code should go back to March folder i.e, 03 Mar 2014 to open recent dated file in that folder.

    This code again and again looking for recent file in current month folder. if there is no file in current month, its not going back to previous month to open recent dated file.

    could please look into this.

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: vba to open recent dated file in a folder

    Change this...
    Please Login or Register  to view this content.
    To this...
    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 04-24-2014 at 01:04 PM.

  9. #9
    Forum Contributor prabhuduraraj09's Avatar
    Join Date
    05-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    330

    Re: vba to open recent dated file in a folder

    Hi AlphaFrog,

    After making the changes yes code picksup previous folder if there is no file in the current month folder.

    I have a Question, request you to clarify ....
    Now i have folders ( 03 Mar 2014, 04 Apr 2014 ). it is working fine.
    What i tried to do is added a one more folder (05 May 2014) for the month of may. But code is not considering this folder.......
    Does this because, code sees the current month folder as per system date?.

    Please clarify.
    Just wanna make sure, so every month if the new folder is created in the same month, no need to change anything in the code.

    Thanks and regards.

  10. #10
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: vba to open recent dated file in a folder

    Quote Originally Posted by prabhuduraraj09 View Post
    Does this because, code sees the current month folder as per system date?.
    Yes .

  11. #11
    Forum Contributor prabhuduraraj09's Avatar
    Join Date
    05-19-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    330

    Re: vba to open recent dated file in a folder

    Hi AlphaFrog,

    Thanks for your continuous support and timely help.
    i completely appreciate your effort.

    Added some stars for you

  12. #12
    Registered User
    Join Date
    05-05-2014
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: vba to open recent dated file in a folder

    hey i have a very similar problem and wondering if you could help me too. I tried using the code written in this thread (making tweaks to adapt) but it does not work.

    Please Login or Register  to view this content.

    The problem is, it doesn't open any files at all. I'm using excel 2010.

    Situation (for clarity if needed): i want a spread sheet to open the latest dated xls file (which are all located in the one folder) and named SDRyyyymmdd accordingly.

    please help

  13. #13
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: vba to open recent dated file in a folder

    Quote Originally Posted by channy.m View Post
    hey i have a very similar problem and wondering if you could help me too. I tried using the code written in this thread (making tweaks to adapt) but it does not work.


    The problem is, it doesn't open any files at all. I'm using excel 2010.

    Situation (for clarity if needed): i want a spread sheet to open the latest dated xls file (which are all located in the one folder) and named SDRyyyymmdd accordingly.

    please help
    The path should end with a \ character.

    strPath = "C:\test\"

    Is your dated file extension .xls and not .xlsx or .xlsm ?

+ 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. vba code to open last dated file
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-23-2014, 07:08 PM
  2. 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
  3. Open multiple dated text files and import dated data specified in file name
    By andygxxxv in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2013, 03:56 PM
  4. 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
  5. 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