szakharov7723
Board Regular
- Joined
- Jun 22, 2018
- Messages
- 85
- Office Version
- 2019
- Platform
- Windows
So surprisingly I didn't find such a simple addition to the save as macro that already exists. So I created it myself.
There is already a macro that does saving as based on value in cell, but when this file already exists it pops up an error if you don't replace the file
My objective was to allow saving it as 2nd file. (there is a reason for that).
So sharing it in case somebody faces the same problem and doesn't know VBA.
Note I also don't know VBA, just learnt it a bit enough to create this one.
There is already a macro that does saving as based on value in cell, but when this file already exists it pops up an error if you don't replace the file
My objective was to allow saving it as 2nd file. (there is a reason for that).
So sharing it in case somebody faces the same problem and doesn't know VBA.
Code:
Option Explicit
Sub SaveAsExample()
Dim FName As String
Dim FPath As String
On Error GoTo Handler:
FPath = Sheets("Sheet1").Range("A2").Text
FName = Sheets("Sheet1").Range("A1").Text
ThisWorkbook.SaveAs Filename:=FPath & "\" & FName
Exit Sub
Handler:
FPath = Sheets("Sheet1").Range("A2").Text
FName = Sheets("Sheet1").Range("A1").Text
ThisWorkbook.SaveAs Filename:=FPath & "\" & FName & "_2"
End Sub
Note I also don't know VBA, just learnt it a bit enough to create this one.