+ Reply to Thread
Results 1 to 8 of 8

Macro Code to Open file with dynamic name (and possibly re-save with different name)

  1. #1
    Registered User
    Join Date
    12-02-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Macro Code to Open file with dynamic name (and possibly re-save with different name)

    I am trying to include in my macro a line of code to open files that I save down daily into a folder. The issue is that everyday they have the same static name, but then have DDMonYYYY-# at the end. Is there a way to make the code dynamic enough to find and open these folders? I would only need for the current day so maybe the today() function can be leveraged on the main sheet I have open to run the macro?

    For Example: the Files are saved to C:\Documents\ with the below names

    ACCOUNTNUM0 - Account Summary Extract - XXXXXXX - 24Dec2013-0.xls
    ACCOUNTNUM1 - Account Summary Extract - XXXXXXX - 24Dec2013-1.xls
    ACCOUNTNUM2 - Account Summary Extract - XXXXXXX - 24Dec2013-2.xls

    Or is there another solution to open these and re-save without the date at the end?

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro Code to Open file with dynamic name (and possibly re-save with different name)

    Try:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-02-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Macro Code to Open file with dynamic name (and possibly re-save with different name)

    This is great, thank you. Is there anyway to make the 0 reference a user inputted cell in another open workbook? i.e. the user types in -2 in workbook "Book 1" Sheet1 to have the current date minus 2 days?

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro Code to Open file with dynamic name (and possibly re-save with different name)

    This uses A1 as the user inputted range value.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-02-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Macro Code to Open file with dynamic name (and possibly re-save with different name)

    again worked great, thanks. One last part - the reports are downloaded automatically to a folder "yyyymmdd" with a -1 date. My macro opens each file then copies certain data. Is there anyway to code this folder dynamically into the file path? So for today the files created a folder 20131225

    an example file path C:\Documents\"This is where i would need the T-1 date folder"\ACCOUNTNUM0 - Account Summary Extract - XXXXXXX - " & Format(DateAdd("d", x, Date), "ddmmmyyyy") & "-0.xls

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro Code to Open file with dynamic name (and possibly re-save with different name)

    Maybe:

    Please Login or Register  to view this content.
    Take out the comment and try.

  7. #7
    Registered User
    Join Date
    12-02-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Macro Code to Open file with dynamic name (and possibly re-save with different name)

    thanks for this!

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro Code to Open file with dynamic name (and possibly re-save with different name)

    Not a problem. You're welcome anytime.

+ 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 save sheet as CSV using a dynamic file name and file path
    By chris.tinta in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-15-2013, 10:45 AM
  2. Macro to open hyperlink and save the file
    By kt090678 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-28-2013, 05:10 AM
  3. VBA/Macro Code needed to open 'Save As' dialogue box and set the file type to CSV
    By daleski in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-24-2013, 12:58 PM
  4. Open File Run Macro and Save
    By nachousa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-08-2010, 05:12 PM
  5. Macro to keep original file open, not 'save as' file
    By LonestarGuy in forum Excel General
    Replies: 4
    Last Post: 06-09-2010, 03:53 PM

Tags for this Thread

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