Custom 'cancel' on Auto_Close

RobbieC

Active Member
Joined
Dec 14, 2016
Messages
376
Office Version
  1. 2010
Platform
  1. Windows
Hi there, I have a 'very customised' spreadsheet which I have replaced all alert boxes with customised userforms.

I have a form called CloseAreYouSure which is triggered when Auto_Close kicks in. This just confirms whether or not the application is to close down with a 'yes' & 'no' button:

Code:
Sub Auto_Close()


CancelAreYouSure.Show
If CancelForm = False Then
    Exit Sub
End If

Application.DisplayAlerts = False
ThisWorkbook.Saved = True
ActiveWorkbook.Close
Application.DisplayAlerts = True

End Sub

If the user chooses 'yes', the sub continues and the program shuts down without the final prompt 'save', don't save' or 'cancel'

But if the user chooses 'no' the Exit Sub doesn't kick in and instead the built-in 'save', don't save' or 'cancel' form appears...

Is there a way of cancelling the Auto_Close without the second 'alert' showing? Or is there a better way to do this?

If you can point me in the right direction, I'd be very grateful

Thanks

Rob
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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