How to save workbook and avoid debug error

mfreak009

New Member
Joined
Sep 21, 2006
Messages
8
Hi all,

I have the below macro for saving a copy of workbook (original wkbk called macro):

Sheet1.Select
Cells.Select
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False

ActiveWorkbook.SaveAs Filename:= _
"\\Daily\Name " & Date & ".xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

ActiveWorkbook.Close

However, if there is already an existing workbook with the same name in path, excel will prompt msg asking if I want to replace with options Yes, No and Cancel. If I choose, No or Cancel, a End or Debug error msg is shown.

How can I configure a macro such that if I select =
No, on prompt - there will not be any end or debug error msg, and excel will do nothing. I can decide what I can to do with the newly create workbook later.

Cancel, on prompt - no end or debug error msg, and excel will not save the newly create workbook (automatically named as book2) but auto delete it, and will direct me back to original workbook.

Thanks!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,136,266
Messages
5,674,722
Members
419,521
Latest member
Jasonnie

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
Top