How to save filename with -v2 -v3 and so on at the end if file name already exists
I have the following code and I want to change it such that:
1) if the file name C:\abc.xlsx already exists, it will save as C:\abc-v2.xlsx;
2) if both the file name C:\abc.xlsx and C:\abc-v2.xlsx already exist, it will save as abc-v3.xlsx;
...so on and so forth.
[VBA]Sub copysavefile()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Sheets(Array("1", "18")).Select
Sheets("37").Activate
Sheets(Array("1", "18")).Copy
Sheets("1").Name = "summary"
Sheets("18").Name = "main"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
ActiveWorkbook.SaveAs Filename:= "C:\abc.xlsx" , FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
MsgBox ("Complete creating " & Range("J2").Value & ".")
ActiveWindow.Close 'ActiveWorkbook.Close savechanges = True
End Sub[/VBA]
Thanks in advance! :friends: