Tommy Random
New Member
- Joined
- Dec 12, 2009
- Messages
- 22
Hi Team,
I am using the following code to save a file with a new name
When there is no existing file with the same name, the file is saved as desired.
When there is an existing file with the same name, a popup arises notifying the user as follows:
A file called 'File Name Specified in cell d4.xlsm' already exists in this location. Do you want to replace it?
If the user selects "Yes", no problem - the file is overwritten.
If the user selects "No", the following popup arises notifying the user as follows:
Run-time error '1004':
Method 'SaveAs' of object'_Workbook' failed.
I would like to modify the above code so that if the user selects "No", the VBA code would terminate without any further popup notification to the user.
(I still want the user the option to overwrite an existing file. So I do not wish to preempt all error handling).
I tried inserting the following line into the above code, but it did not help:
If Filename = "False" Then Exit Sub
Any suggestions?
Thank you.
I am using the following code to save a file with a new name
Code:
Private Sub CommandButton1_Click()
CommandButton1.BackColor = 5950882
ActiveWorkbook.SaveAs (Range("d4").Value & ".xlsm")
End Sub
When there is no existing file with the same name, the file is saved as desired.
When there is an existing file with the same name, a popup arises notifying the user as follows:
A file called 'File Name Specified in cell d4.xlsm' already exists in this location. Do you want to replace it?
If the user selects "Yes", no problem - the file is overwritten.
If the user selects "No", the following popup arises notifying the user as follows:
Run-time error '1004':
Method 'SaveAs' of object'_Workbook' failed.
I would like to modify the above code so that if the user selects "No", the VBA code would terminate without any further popup notification to the user.
(I still want the user the option to overwrite an existing file. So I do not wish to preempt all error handling).
I tried inserting the following line into the above code, but it did not help:
If Filename = "False" Then Exit Sub
Any suggestions?
Thank you.