添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
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.
Thank you JoeMo for your interest in this question.
The code given is the code I am using in its entirety.
If a file name already exists, Excel itself generates the popup message:
A file called 'File Name Specified in cell d4.xlsm' already exists in this location. Do you want to replace it? (Yes, No, and Cancel options are given.)
Up to the point where that message is generated, all is well as I wish the user to retain the option to decline overwriting a file.
When the user selects "No" (or "Cancel") Excel generates another popup message (which is the one I would like to eliminate or bypass).
Cell D4 contains this formula: ="Assignments "&D1&" "&D2
Cells D1 and D2 contain text, a students first name in D1 and a students last name in D2.
So the value in Cell D4, for example, would be (text) "Assignments Tommy Random"
Thanks.
 Private Sub CommandButton1_Click()CommandButton1.BackColor = 5950882
On Error Resume Next
ActiveWorkbook.SaveAs (Range("d4").Value & ".xlsm")
On Error GoTo 0
End Sub
I consider this question resolved.
I wanted to edit my last post but couldn't remember how to do so.
I found that Application.DisplayAlerts = False
does not allow the user to choose whether or not to overwrite an existing file with the same name. Instead, the file is overwritten without warning.
Again. Thank you for your interest in my question.

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back