Button Saves a version of the Workbook

hamistasty

Board Regular
Joined
May 17, 2011
Messages
208
I'm trying to figure out how to make a macro that once pressed saves a copy of the workbook in the same folder it currently exists in as it's name with "Version x" and the date on the end.

For example, it could originally be called:
Workbook.xlsm

And once the button was clicked it would be saved as a new copy as:
Workbook - Version 1.1 - 21.06.11.xlsm

and the next time it is clicked it would create a new file:
Workbook - Version 1.2 - 21.06.11.xlsm

I'll take a stab at how this would work:
If the filename does not have the string "Version" in it then it adds it's own string to the end starting at 1.0.
If the filename has the string "Version" in it then it figures out what number it is, ie. "1.14" and changes it to 1.15 then resaves it.

I'm not sure how the date system would work. I Guess it could look for the string in the format of xx.xx.xx and delete that and rename it to the current date. Or because it's always going to be "Version 1.xx - xx.xx.xx" it could delete everything right of the Version string and just insert the date in regardless.

I would appreciate any help with this! :)
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this :

Code:
Sub SaveVersionCopy()

    Dim lVersion As Long
    
    On Error Resume Next
        lVersion = 1
        lVersion = Evaluate("LastVersion") + 1
    On Error GoTo 0
    
    With ThisWorkbook
    .SaveCopyAs .Path & "\" & Left(.Name, InStrRev(.Name, ".") - 1) & _
    " - Version 1." & lVersion & " - " & Format(Date, "dd.mm.yy") & ".xlsm"
    End With
    
    Names.Add "LastVersion", lVersion, False
    
    ThisWorkbook.Save

End Sub
 
Last edited:
Upvote 0
Brilliant. That works exactly how I wanted it to. Thanks.

How do I change these to [SOLVED] once someone has helped?
 
Upvote 0
Brilliant. That works exactly how I wanted it to. Thanks.

How do I change these to [SOLVED] once someone has helped?

Glad it worked for you.

I don't know how to change the thread to SOLVED . Maybe you have to contact one of the Forum administrators.
 
Upvote 0
You don't need to !!
A simple response is adequate.
And if I wasn't working on a dinosaur, I might have had time to get a response in as well !!
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,256
Members
452,901
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top