+ Reply to Thread
Results 1 to 5 of 5

Developing a Connection to a Varying File Name (VBA)

  1. #1
    Registered User
    Join Date
    03-29-2012
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    11

    Developing a Connection to a Varying File Name (VBA)

    Hey all. Thanks in advance.

    Here is my issue: I am working with an Excel file that will need to create a data connection to another file and import it into a tab titled "Master Staff". The file location will always be the same, but the file name will change, based on date. It will have the following naming format: "* MM-DD-YYYY HH-MM-SSSS".

    I am really having trouble figuring out the VBA coding for this. The date/time will always change and I want to pull the file with the name that is closest to Now().

    Any thoughts?

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: Developing a Connection to a Varying File Name (VBA)

    You could have a control sheet with the location (folder) where the files exist. You could then have a routine to loop through that folder and record the file names in the control sheet. Once you have a list, you could then do a VLOOKUP or INDEX/MATCH to find the nearest matching file name. Once you have that, open the file.

    I suspect that, rather than storing the file names in the control sheet, you could use an array but I doubt it would be that much faster.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    03-29-2012
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Developing a Connection to a Varying File Name (VBA)

    My issue is that ultimately I need to pull data from a workbook that has a filename with a date that is the most recent. So, I need to import that data to complete my table.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: Developing a Connection to a Varying File Name (VBA)

    I've explained how you could go about locating and matching the file. What you do with it once you have found it and opened it is up to you.

    Regards

  5. #5
    Registered User
    Join Date
    03-29-2012
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Developing a Connection to a Varying File Name (VBA)

    Can anybody offer advice involving a VBA formula where I can open the most recent file without it being a manual process? My preference is that the file is not opened at all and instead I can just import the necessary data based on an array and for-next loop I will create. The difficult part has been actually opening up what is needed.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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