+ Reply to Thread
Results 1 to 9 of 9

Macro to save duplicate file and create folder name based on cell value

  1. #1
    Registered User
    Join Date
    11-22-2009
    Location
    Newcastle,England
    MS-Off Ver
    Excel 2003
    Posts
    78

    Macro to save duplicate file and create folder name based on cell value

    I currently use the following code to create a duplicate file based on two cells within a directory and folder i specify. These cells consist of the team and week commencing date (mondays date of week which is cell 'Main Menu'!K8)


    Please Login or Register  to view this content.
    However I now want to be able to create an archive of past weeks duplicates by creating a folder based on the week commencing date ('Main Menu'!K8). I want the above macro to first check if the folder exists and if not to create it with the date ('Main Menu'!K8), if it does to simply save itself to that folder.

    Thanks for any help
    Last edited by munkee; 11-26-2009 at 04:03 AM.

  2. #2
    Registered User
    Join Date
    11-22-2009
    Location
    Newcastle,England
    MS-Off Ver
    Excel 2003
    Posts
    78

    Re: Macro to save duplicate file and create folder name based on cell value

    code updated with tags

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro to save duplicate file and create folder name based on cell value

    Hello munkee,

    Will the new path be using the working directory?
    Example
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    11-22-2009
    Location
    Newcastle,England
    MS-Off Ver
    Excel 2003
    Posts
    78

    Re: Macro to save duplicate file and create folder name based on cell value

    The directory will be \\dfz70588\106124001\workgroup\Fraud Error Strategy Team\Recovery\Roll up work\testfolder\ Basically it will save the duplicate file to a folder with the name based on the same cell reference that the duplicate file is saved as (the week commencing date).

    So all files saved as teamname-weekcommeningdate.xls will be saved in the folder with the weekcommendingdate e.g. 23.11.2009

    Then the next week the cell value containing the week commencing date value is change to that mondays date and the files then save with that date attached to that folder name.


    e.g.

    FR1-23.11.2009.xls
    RA10-23.11.2009.xls

    will all save to a folder created 23.11.2009 if the folder exists then it should not try to create a new one but just add the file to it. If it does not exist it should create it and add to it.

    Giving total path to a file name \\dfz70588\106124001\workgroup\Fraud Error Strategy Team\Recovery\Roll up work\testfolder\23.11.2009\FR1-23.11.2009.xls

    In the code in the first post the DD.MM.YYYY is simply the formatting for the way the date will be appended to the filename.
    Last edited by munkee; 11-25-2009 at 06:09 PM.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro to save duplicate file and create folder name based on cell value

    Hello munkee,

    It has been a hectic day since tomorrow is Thanksgiving Day here in the states and for most people is a 4 day holiday.
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 11-25-2009 at 10:08 PM. Reason: Corrected typo

  6. #6
    Registered User
    Join Date
    11-22-2009
    Location
    Newcastle,England
    MS-Off Ver
    Excel 2003
    Posts
    78

    Re: Macro to save duplicate file and create folder name based on cell value

    I will give this a go today at work and get back to you thanks.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro to save duplicate file and create folder name based on cell value

    Hello munkee,

    I just noticed that the parent path has a back slash on the end. That should be removed. It should look like below...
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-22-2009
    Location
    Newcastle,England
    MS-Off Ver
    Excel 2003
    Posts
    78

    Re: Macro to save duplicate file and create folder name based on cell value

    Works perfectly thanks LR

  9. #9
    Registered User
    Join Date
    04-17-2012
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    7

    Smile Re: Macro to save duplicate file and create folder name based on cell value

    Hello Leith Ross,

    I'd like to know if it is possible to create a macro (assigned to a button) that would create a new folder onto this directory:

    "\\s009\mimx\DTMS\DTMS_2012\Europa\França\Propostas\Budgets"

    and that it's name would be the on the cell

    "F9" - eg. "B112-2012".

    After that just save a copy of that document onto that directory!


    Thanks a lot! http://www.excelforum.com/images/icons/icon7.png

    Tiago

+ 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