+ Reply to Thread
Results 1 to 4 of 4

Save file by incremental file name

  1. #1
    Forum Contributor
    Join Date
    07-01-2009
    Location
    Maine, USA
    MS-Off Ver
    Excel 2016
    Posts
    161

    Save file by incremental file name

    I have workbooks that I use a "_v##" for versioning (yes, I know I can use version control, but in this instance, I can't). This is how I need to use this macro...

    The opened file will have a name something like "2019-TestFile_v13.xlsx". When the macro runs, I would like for it to save it by automatically increment the _v portion. In this instance, it would need to save as "2019-TestFile_v14.xlsx". If "2019-TestFile_v14.xlsx" already exists, then it should try to save it as "2019-TestFile_v15.xlsx" and so forth until it is able to save it to a new file.

    Keep in mind there may or may not be the previous files in the same directory (such as "2019-TestFile_v9.xlsx").

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Save file by incremental file name

    Just store in some out of way sheet/cell the incremental number. And use that in your variable.

    Alternately... if all files are kept in same folder. You could use DIR() function to count # of files that match "2019-TestFile_v*.xlsx" pattern.

    Though, 1st method is easier to maintain and less prone to error, if file(s) gets moved from target folder.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Save file by incremental file name

    This might do what you're after for the active workbook:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

  4. #4
    Forum Contributor
    Join Date
    07-01-2009
    Location
    Maine, USA
    MS-Off Ver
    Excel 2016
    Posts
    161

    Re: Save file by incremental file name

    Thanks WideBoy!

+ 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. [SOLVED] check if file exists using fso. then save with an incremental number
    By john34 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-13-2014, 09:32 AM
  2. Problem With Open File and Save File With Saveas and then close the File
    By John Vieren in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-27-2013, 12:53 AM
  3. Replies: 1
    Last Post: 09-05-2013, 02:39 PM
  4. Save as macro that specifies file type, file location and takes file name from three cells
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-13-2013, 10:09 PM
  5. Replies: 0
    Last Post: 01-27-2013, 12:13 PM
  6. Replies: 1
    Last Post: 10-01-2012, 11:46 PM
  7. How to: Open file, format data, save file, close file and repeat.
    By thexeber in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-11-2010, 12:56 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