ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Choosing no when asked to overwrite an existing file? (https://www.excelbanter.com/excel-programming/403712-choosing-no-when-asked-overwrite-existing-file.html)

Carl

Choosing no when asked to overwrite an existing file?
 
I'm trying to write a piece of code that tells the macro to automatically
choose "no" when ever the following message comes up while a macro is being
run:

"The file ... already exists. Do you want to replace the existing file?"

And then to give a message box saying that you can't overwrite an existing
file and end the sub.

Is it an IF statement?

The reason this message will come up while the macro is running is because
the person has chosen the wrong date from the drop down box. It won't come
up if they choose the right date because the file won't exist.

GTVT06

Choosing no when asked to overwrite an existing file?
 
On Jan 5, 10:36*am, carl wrote:
I'm trying to write a piece of code that tells the macro to automatically
choose "no" when ever the following message comes up while a macro is being
run:

"The file ... already exists. *Do you want to replace the existing file?"

And then to give a message box saying that you can't overwrite an existing
file and end the sub.

Is it an IF statement?

The reason this message will come up while the macro is running is because
the person has chosen the wrong date from the drop down box. *It won't come
up if they choose the right date because the file won't exist.


If Dir("C:\Enter your save as criteria here\Book.xls") < "" Then
MsgBox "You can't overwrite an existing file"
Exit Sub
Else
ActiveWorkbook.SaveAs Filename:= _
"C:\Enter your save as criteria here\Book.xls",
FileFormat:=xlNormal
End If


All times are GMT +1. The time now is 06:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com