VBYesNoCancel Dialog Box Giving giving dreaded run-time error

josephzenten

New Member
Joined
Jul 25, 2018
Messages
2
Hello All,

I am new to this forum and have come seeking your advice.

As my title suggest I am currently trying to override my previous save file that is saved in a specific location. However, it is not always the case that I want to save it in the specified location but instead am trying to run the bulk of my macro. But when I click either No, or Cancel I am provided an error : /


The following is the save path, and file name. Please note that the file name is not exactly 'MyFile', but it is to always be saved with a similar name:
ActiveWorkbook.SaveAs Filename:="C:\Users\zent\Desktop\MyFile.xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

When I click on "No" when the Yes, No, Cancel dialog appears I am then given run-time error '1004' : /

I have been trying to add to work with the MsgBox properties but I haven't been able to accomplish anything yet. Is there any way for me to be able to click on either No, or Cancel without being given this run time error when I run the Macro ?

Thank you in advance!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
It would be useful if you supplied the rest of your code. Especially the part where you click yes/no/cancel.

When posting code please use code tags, the # icon in the reply window
 
Upvote 0
Thank you!

This is strange I thought I replied to your post...

Anyways!

The following is the code when I am trying to save my file in a specified location#

# ChDir "C:\Users\azenteno\Desktop" ActiveWorkbook.SaveAs Filename:="C:\Users\azenteno\azent.csv", _
FileFormat:=xlCSV, CreateBackup:=False

The problem arises when their is a file already in that location. Most of the time I am okay with replacing it, since I run an FTP batch that retrieves the file from that location and looks at that specific file name. But the issue arises when I DON'T want to replace it. I receive the following dialog box:

"A file named 'C:\Users\azenteno\azent.csv' already exists in this location. Do you want to replace it?
Yes, No, Cancel"

If the user of the macro clicks on either No or Cancel I get the following run time error:

"Microsoft Visual Basic
Run-time error '1004':
Method 'SaveAs' of object '_Workbook' failed
Continue, End, Debug, Help"

All I want to be able to do at this point is allow the user of the macro to be able to click on either No, or Cancel without this run time error appearing : /
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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
Back
Top