netrixuser
Board Regular
- Joined
- Jan 21, 2019
- Messages
- 77
- Office Version
- 365
- Platform
- Windows
Hello,
Although my code works I am trying, gradually, to make it more efficient, and I am at the stage where I want to do something if, during the File "save as" command, the user does not want to overwrite an existing file or presses cancel.
My code for saving the workbook is:
In cell A104 on the Index sheet I have a concatenation of a couple of cells to produce the text "(Current Month)-(Current Year) <current month=""><current year="">Monthly MRL Reconciliation"
Today that produces Apr-2019 Monthly MRL Reconciliation and, without my intervention, it saves it with an xlsm extension
If, at the file save as prompt, there is already a file existing with the same name I get a popup saying as much, if No or Cancel is selected the code crashes with:
I found a post regarding this on the site and have now added some code to stop it crashing, but I would like to be able to give the user the options of:
The code to stop the script crashing when either No or Cancel is selected is
I now need assistance to write some "stuff" after EH1:
Any help gratefully received !!
Regards
Netrix</current></current>
Although my code works I am trying, gradually, to make it more efficient, and I am at the stage where I want to do something if, during the File "save as" command, the user does not want to overwrite an existing file or presses cancel.
My code for saving the workbook is:
Code:
FPath = "C:\Users\" & Environ$("UserName") & "\Downloads"
FName = Sheets("Index").Range("A104").Text
ThisWorkbook.SaveAs Filename:=FPath & "\" & FName
In cell A104 on the Index sheet I have a concatenation of a couple of cells to produce the text "(Current Month)-(Current Year) <current month=""><current year="">Monthly MRL Reconciliation"
Today that produces Apr-2019 Monthly MRL Reconciliation and, without my intervention, it saves it with an xlsm extension
If, at the file save as prompt, there is already a file existing with the same name I get a popup saying as much, if No or Cancel is selected the code crashes with:
Run-time error '1004'
Method 'SaveAs' of Object'_Workbook' failed
Method 'SaveAs' of Object'_Workbook' failed
I found a post regarding this on the site and have now added some code to stop it crashing, but I would like to be able to give the user the options of:
1) cancelling the save as and finishing the script -which is what the extra code below does
2) saying No to the overwrite question, and being prompted to change the filename - which I am struggling with tbh.
2) saying No to the overwrite question, and being prompted to change the filename - which I am struggling with tbh.
The code to stop the script crashing when either No or Cancel is selected is
Code:
Sub Get_Reports()[INDENT]On error GoTo EH1
'My Code
[/INDENT]
[INDENT]EH1:[/INDENT]
End Sub
I now need assistance to write some "stuff" after EH1:
Any help gratefully received !!
Regards
Netrix</current></current>