Hi all,
I am using macro to save active workbook in specific folder. String from input box is inserted in front of original workbook name. Now it works great, but some users started to save same file multiple times and I need to adjust it to create new version instead.
When they save it with "Test" string in input box it goes like:
Test OriginalName.xlsx
Test Test OriginalName.xlsx
but it should create Test OriginalName v2.xlsx instead.
Any ideas how to improve it?
I am using macro to save active workbook in specific folder. String from input box is inserted in front of original workbook name. Now it works great, but some users started to save same file multiple times and I need to adjust it to create new version instead.
When they save it with "Test" string in input box it goes like:
Test OriginalName.xlsx
Test Test OriginalName.xlsx
but it should create Test OriginalName v2.xlsx instead.
Any ideas how to improve it?
VBA Code:
Private Sub CommandButton13_Click()
On Error GoTo Err
Dim NewName As String
NewName = InputBox("Insert Number", "Change file's name")
Dim CurrentName As String
CurrentName = ActiveWorkbook.Name
Dim ws As Workbook
Set ws = ActiveWorkbook
If ActiveWorkbook.Name Like "Book*" Then
ws.SaveAs "C:\General\" & NewName
Else
ws.SaveAs "C:\General\" & NewName & " " & CurrentName
End If
Err:
Unload Me
End Sub