+ Reply to Thread
Results 1 to 12 of 12

Open file when file path contains dates

  1. #1
    Registered User
    Join Date
    05-10-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    68

    Open file when file path contains dates

    Hi all,

    Having an issue getting the correct logic to open a file path that changes each month and year, examples below and start of effort.

    I am checking if the file exists, and if so, then open

    The date at the end of the path needs to be fool proof, so 8 July (d mmm) as well as 08 July (dd mmm)

    The FY20 stands for Full Year 2020 which changes monthly, i.e. we are in July now.

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


    Thanks for the help in advance
    Last edited by heathb; 07-09-2019 at 11:05 AM. Reason: Cannot reply

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Open file when file path contains dates

    Well... your issue is that folder naming convention isn't consistent.

    8 July 19. Is not "dd mmm yy" format, but "dd mmmm yy". However, Jan is in "dd mmm yy" format.

    You'll either have to check for both patterns or make sure folders use consistent format.
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  3. #3
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Open file when file path contains dates

    May need some more help on how you decide:

    - Which financial year we are in (i.e. when does it start - January? April?)
    - When you use the full month name (e.g. July) vs. the abbreviation (e.g. Jan)

    For example, the below will generate OK for July but not for January if you're using "Jan"

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Open file when file path contains dates

    Hi there,

    Does the following code do what you need?

    Please Login or Register  to view this content.
    The highlighted values may be changed to suit your requirements.


    Hope this helps - please let me know how you get on.

    Greg M

  5. #5
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,309

    Re: Open file when file path contains dates

    Another possible solution (bold = changes)...
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    05-10-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Open file when file path contains dates

    Thanks all, however none of the above finds the file, just opens the message box

    Debug tells me the Expression YEAR is not defined!

    Should it be in quotes?
    Last edited by heathb; 07-09-2019 at 11:04 AM.

  7. #7
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,309

    Re: Open file when file path contains dates

    Try this one...
    Please Login or Register  to view this content.

  8. #8
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Open file when file path contains dates

    Hi again,

    Many thanks for your feedback and also for the Reputation increase - much appreciated

    Best regards,

    Greg M

  9. #9
    Registered User
    Join Date
    05-10-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Open file when file path contains dates

    Hi Dangelor,

    Still cannot find the file

  10. #10
    Registered User
    Join Date
    05-10-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Open file when file path contains dates

    Quote Originally Posted by dangelor View Post
    Another possible solution (bold = changes)...
    Have got the date working, so it is looking at OHS2 correctly, however, when it looks at Len(Dir(OHS))=0 it goes to message box

    Have edited the code to be mmmm rather than mmm

    Unfortunately, I cannot see the whole of the path when hovering over it.

    When I use "K:\Reconciliation Team\Client\Year Ending 2019\FY19 July 19\BOI\" & Format(TDate, "d mmmm yy") & "\312 - EPFX Posting\BalanceAndTransactionReport.csv"
    The report opens correctly
    Last edited by AliGW; 07-10-2019 at 10:25 AM. Reason: Please don't quote unnecessarily!

  11. #11
    Registered User
    Join Date
    05-10-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    68

    Re: Open file when file path contains dates

    I have it working finally, many thanks for your help and putting up with me Expect any errors was down to myself

    the following works
    Please Login or Register  to view this content.

  12. #12
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,309

    Re: Open file when file path contains dates

    Glad that I was of some help. Thanks for letting me know!

+ 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] Using Workbook.Open to open an excel file with a variable path
    By walt737 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-27-2019, 01:01 PM
  2. Automatically open a file in a specific file path when another sheet is opened
    By joshnathan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-20-2014, 11:05 AM
  3. Replies: 5
    Last Post: 09-29-2012, 12:40 PM
  4. VBA Changing a fixed file path with open file dialog box
    By Dan27 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2011, 08:54 AM
  5. open file path
    By Bigelk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2011, 09:00 AM
  6. Open Word file form Excel using VBA and file path
    By psychoPETE in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-05-2010, 07:02 PM
  7. Saving file to same path as open file
    By Glio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-19-2007, 04:57 AM

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