Hi All,
The exact opposite of this question has been asked many times, and I have used the solution... but the time has come where I need to know if the user has selected No or Cancel to overwrite an existing File.
I do not want to hide this alert.
when using the code:
If the file already exists and a user selects "yes" then excel does it's thing and saves the file.
If the user selects "no" or "cancel" then an error occurs. Which can be trapped.
I am unsure how to delineate between the user selecting no or cancel. If they select no, then my code will go into:
and if they click cancel, I plan to exit sub...
Although clicking no/cancel returns an excel error, near as I can tell, it is a generic "Method 'Save As' of Object '_Workbook' failed" and not a specific error code response for the seperate no/cancel buttons.
One idea I had was to preemptively display the overwrite dialog box and store the users response as a variable, but I'm not sure if this is even possible.
Thanks,
Mike
Windows 7
Excel 2007-2010
The exact opposite of this question has been asked many times, and I have used the solution... but the time has come where I need to know if the user has selected No or Cancel to overwrite an existing File.
I do not want to hide this alert.
when using the code:
Code:
Application.ActiveWorkbook.SaveAs (SaveName)
If the file already exists and a user selects "yes" then excel does it's thing and saves the file.
If the user selects "no" or "cancel" then an error occurs. Which can be trapped.
I am unsure how to delineate between the user selecting no or cancel. If they select no, then my code will go into:
Code:
SaveName = Application.GetSaveAsFilename()
and if they click cancel, I plan to exit sub...
Although clicking no/cancel returns an excel error, near as I can tell, it is a generic "Method 'Save As' of Object '_Workbook' failed" and not a specific error code response for the seperate no/cancel buttons.
One idea I had was to preemptively display the overwrite dialog box and store the users response as a variable, but I'm not sure if this is even possible.
Thanks,
Mike
Windows 7
Excel 2007-2010