+ Reply to Thread
Results 1 to 6 of 6

check if file exists and opening it based on file date

  1. #1
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    check if file exists and opening it based on file date

    Hi guys,

    I'm trying to create some code that opens a file from a network location, based on filename / date.

    First, I have userform input from the user that determines a weeknumber, year and company that he or she wants to see the analysis from - this constructs the network path where the files are :

    so, the path will be something like this :
    \\networklocation\information\2014\CompanyX\Week_12\Analyse
    where the bold parts are gathered through userform input

    What I'd like to have is a code that
    • checks if that network location is there
    • checks if one or multile files containing the word "doorverkoop" are in that location
    • opens the file with the word "doorverkoop" in it that has the most recent file date
    • if the file or network location are not found, have a popup allow the user to open a file he or she wants to import

    Since I'm not great with file handling in VBA, I'd appreciate it if anyone can help me out / point me in the right direction.
    Thanks so much in advance!!
    Please click the * below if this helps

  2. #2
    Forum Contributor
    Join Date
    04-24-2012
    Location
    Karlstad, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    232

    Re: check if file exists and opening it based on file date

    Maybe this can help you some. I believe a more experienced person might have another suggestions. But until someone else answer, this can help you further.

    Following code looks for all files containing "*.xls" in path "C:\Temp". Change to your path and to "*doorverkoop*" in your code

    Due to I don't know your filename containing date, I have left that part. I open the last file in my array.

    Please Login or Register  to view this content.
    1. Reply to thread and inform if suggestion was helpful or not
    2. Click on the star (=Add Reputation) if you think someone helped you
    3. Mark [SOLVED] to this thread if solution was found. (On Menu "Thread Tools" > "Mark this thread as solved")

  3. #3
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: check if file exists and opening it based on file date

    Hi Joakim,

    thanks for your reply - but actually proofing which of the files has the latest file date is the key part I want to do
    Anyone can help on that, please?

  4. #4
    Forum Contributor
    Join Date
    04-24-2012
    Location
    Karlstad, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    232

    Re: check if file exists and opening it based on file date

    Is the date included in the filename or is it when it was saved? If the date is a part of the filename, please provide an example.

    Quote Originally Posted by JasperD View Post
    Hi Joakim,

    thanks for your reply - but actually proofing which of the files has the latest file date is the key part I want to do
    Anyone can help on that, please?

  5. #5
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: check if file exists and opening it based on file date

    How about something like this to get you started..?

    Change file path to suit..

    The "O-D" part of the command will sort the files in order of date and time (earliest first)..

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    04-24-2012
    Location
    Karlstad, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    232

    Re: check if file exists and opening it based on file date

    I think apo's solution is great.

    I just want to show it is possible to use Dir() with function FileDateTime() also. Notice that the code beneath is checking for *.xls* in path C:\Temp\.

    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. Macro to check file exists and take input from the file
    By naidu9295 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-12-2010, 08:15 AM
  2. Check if file exists
    By v2jtb in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-25-2010, 09:22 AM
  3. Check to see if a file exists
    By ChrisMattock in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-09-2007, 04:22 AM
  4. FILE EXISTS ERROR in opening Excel
    By msuryexcel in forum Excel General
    Replies: 1
    Last Post: 12-23-2005, 12:10 PM
  5. check if file exists
    By Curt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2005, 01:10 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