Macro to save workbook and previous versions

PaulS

Board Regular
Joined
Feb 26, 2006
Messages
66
Hi experts,
I was looking for a macro to save a workbook, but also the previous generation. I searched this board and other internet sites but have not found the solution.
I know how to save a workbook, but I was looking for the code to find the existence of previous versions ( the -1 and -2 version).

What I want is something like this:

Sub Savexls()
Xls = filename
If “xls-2” exists then rename as “xls-3” (means overwrite existing xls-3)
If “xls-1” exists then rename as “xls-2”
Rename xls as “xls-1”
Save Xls
"End Excel ??
End Savexls

Where "End Excel" is it possible that the macro closes Excel??

I assume that somewhere such a macro is "on the shelf"

Thanks for your help.
Paul
 
I am working on the macro.
Question: How do I check the existence of a file without opening it? Is that possible?
Thanks,
Paul
 
Upvote 0
I have one that works by checking the file path and name. If the filepath and name = the default, then the file updates a cell (e.g invoice number) resaves as default, then again resaves - renaming itself with the new invoice number.

This keeps the master template untouched and automatically resaves the new invoice in a backup directory. this requires having the template and the backup in 2 different directories.

Is this the sort of thing you are looking for?
 
Upvote 0
What I am looking for is as described above:
I want to check the existence of e.g. filename-1 ; if exists then rename to filename-2; and so on. This to create 3 generations of the workbook.
I can probably use parts of your code: 1) check existence and 2) rename a file.
Thanks for your help.
Paul
 
Upvote 0

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