+ Reply to Thread
Results 1 to 8 of 8

Save a the same workbook but add a variable number at the end

  1. #1
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Save a the same workbook but add a variable number at the end

    HI, I want to save down a template as the same named file. each time I save it I want to save it with an incremental variable number\

    example
    "myworkbook ver 1"
    "myworkbook ver 2"

    This is what I'm trying to leverage and build on but I am stuck...

    this just keeps adding .xlsx to the same file, not different versions



    Please Login or Register  to view this content.
    Please Help

  2. #2
    Forum Contributor
    Join Date
    01-20-2012
    Location
    Amsterdam, The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    186

    Re: Save a the same workbook but add a variable number at the end

    Hi Swade,

    I usually append this to my filename:
    Please Login or Register  to view this content.
    Does that suit your needs?
    Regards,
    Rick

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

    Re: Save a the same workbook but add a variable number at the end

    Maybe:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Save a the same workbook but add a variable number at the end

    My code assumes you have a file named something like this.
    C:\MyFolder\MyFileRev1.xls

    Fpath returns the full path seen above.

    My code initially looks for "Rev" in fpath

    If you had a brand new file that didn't have Rev in the path you could check for that and name it Rev1 and bypass the rest of the code.

    Then the newName line concatenates the 2 onto the original file name on the first loop. Dir checks if the file exists. With Dir if the file exists already it will return the file name, otherwise it returns "". So by checkingfor "" we confirm the file doesn't exist. revNumber will just keep changing until it finds the first rev number file that doesn't exist and once it does it saves the file and exits the loop.

    Please Login or Register  to view this content.
    Last edited by skywriter; 09-14-2015 at 04:11 PM.

  5. #5
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Save a the same workbook but add a variable number at the end

    Quote Originally Posted by JOHN H. DAVIS View Post
    Maybe:

    Please Login or Register  to view this content.



    The below Line confuses me it is making file2 value as "." in the Locals window
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Save a the same workbook but add a variable number at the end

    Quote Originally Posted by rkey View Post
    Hi Swade,

    I usually append this to my filename:
    Please Login or Register  to view this content.
    Where would I insert this?

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

    Re: Save a the same workbook but add a variable number at the end

    My mistake. Should be:

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Save a the same workbook but add a variable number at the end

    Quote Originally Posted by JOHN H. DAVIS View Post
    My mistake. Should be:

    Please Login or Register  to view this content.
    No worries, Marking this Thread as solved

+ 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. Save workbook as variable/pass argument to another module
    By crossfitciaran in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-06-2015, 07:40 PM
  2. [SOLVED] Calculate average of variable number of cells variable number of times
    By WeirnetherlandsBart in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-06-2014, 10:11 AM
  3. [SOLVED] Multiple workbooks into one workbook - asked to save or not save each workbook step remove
    By Benji Jeff in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-20-2014, 09:54 PM
  4. Macro for copying & inserting a variable number of rows into a separate workbook
    By Gunther Maplethorpe in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-01-2013, 06:26 PM
  5. [SOLVED] VBA extract X number of rows and save as new workbook
    By freud1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2012, 07:21 AM
  6. Save workbook using variable for save as and for a new folder name
    By TheNewGuy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-03-2009, 10:53 AM
  7. Save average() of a variable selection to a variable
    By ebahr in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-10-2008, 07:15 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