ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vba Cancel Save As (https://www.excelbanter.com/excel-programming/405022-vba-cancel-save.html)

JAO

vba Cancel Save As
 
I have written a macro that shows the Save As dialogue box, but I'd like to
add code that closes a workbook if the user selects "cancel".

Can anyone help?

Matthew Pfluger

vba Cancel Save As
 
When using the GetSaveAsFilename method, the method returns FALSE if the user
clicks Cancel. Thus, you only need to check the result of the method.

Dim response
response = Application.GetSaveAsFilename

if not response then
' User clicked false
Workbooks(NumberOrNameHere).close
else
' Do stuff
End if

HTH,
Matthew Pfluger

"JAO" wrote:

I have written a macro that shows the Save As dialogue box, but I'd like to
add code that closes a workbook if the user selects "cancel".

Can anyone help?



All times are GMT +1. The time now is 03:30 AM.

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