I have a piece of code which copies a worksheet from an Excel workbook and saves this as a text file with the file path and file name being dynamically pulled from two cells.
I want to know how to adjust this code so when the file already exists a new version will be saved. Ie: Initially the code will save the file as "2016_11_17_v1" but if this exists save as "2016_11_17_v2" etc.
Is this possible? Any help would be MUCH appreciated.
I want to know how to adjust this code so when the file already exists a new version will be saved. Ie: Initially the code will save the file as "2016_11_17_v1" but if this exists save as "2016_11_17_v2" etc.
Is this possible? Any help would be MUCH appreciated.
Code:
Sub SaveAs()
SaveAsFilePath = Range("A1") & "\" & Range("A2") & ".txt"
If Range("Operator_Check") = 1 Then
MsgBox "Operators missing from rates table"
Exit Sub
Else
On Error Resume Next
ActiveWorkbook.Worksheets("Wokrsheet_1").Copy
ActiveWorkbook.SaveAs SaveAsFilePath, xlTextWindows
ActiveWorkbook.Close
On Error GoTo 0
End If
End Sub