SaveCopyAs add new copy if Name already exists

mellie79

New Member
Joined
Feb 6, 2018
Messages
2
Hello

I have 3 Macros in my work book. Each one is for a shift(1,2,3) user to save a copy as the following:

ActiveWorkbook.SaveCopyAs ("T:\Mellie79\MFG Schedule\Bulk Synthesis MFG Schedule 1st Shift-" & Format(Now(), "DD-MMM-YYYY") & ".XLSM")

Typically the user would only save once a shift, however in cases were they would save more than once or click the wrong submit button I would like excel to replace the file with the same name plus a verison # or letter. I have searched Google and the forums but have not been successful in making this happen.

Anyone with thoughts?

Thx
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How about adding a time stamp to your date...

Code:
Format(Now, "yyyy-mm-dd hh-mm-ss")

???
 
Upvote 0
I do something similar and use code like this:

Code:
'save the file, taking into account that there may already be a file with the intended name, in which case just add "(2)" after it,
'allowing for up to 4 iterations.
    If Len(Dir(folder_to_save_to & file_name_to_save_as & ".xlsm", vbDirectory)) < 1 Then
        ActiveWorkbook.SaveAs Filename:=folder_to_save_to & file_name_to_save_as & ".xlsm", FileFormat:=52
    ElseIf Len(Dir(folder_to_save_to & file_name_to_save_as & "(2)" & ".xlsm", vbDirectory)) < 1 Then
        ActiveWorkbook.SaveAs Filename:=folder_to_save_to & file_name_to_save_as & "(2)" & ".xlsm", FileFormat:=52
    ElseIf Len(Dir(folder_to_save_to & file_name_to_save_as & "(3)" & ".xlsm", vbDirectory)) < 1 Then
        ActiveWorkbook.SaveAs Filename:=folder_to_save_to & file_name_to_save_as & "(3)" & ".xlsm", FileFormat:=52
    ElseIf Len(Dir(folder_to_save_to & file_name_to_save_as & "(4)" & ".xlsm", vbDirectory)) < 1 Then
        ActiveWorkbook.SaveAs Filename:=folder_to_save_to & file_name_to_save_as & "(4)" & ".xlsm", FileFormat:=52
    End If
 
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,656
Members
449,091
Latest member
peppernaut

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