PDA

View Full Version : [SOLVED:] An application.EnableEvents issue. Help needed.



stranno
10-08-2018, 11:03 AM
Hi All,

Does someone know how to close a workbook without saving changes if Application.EnableEvents is set to False (when opening the worbook).

And how to set it back to Application.EnableEvents = True, just before closing the workbook.
Seems impossible to do. But maybe someone knows a workaround?

The thing is, Private Sub Workbook_BeforeClose(Cancel As Boolean) does not respond if EnableEvents = False.

regards,
Stranno

mancubus
10-09-2018, 07:07 AM
which codes do not run as a result of the disabled events?

post all the codes or workbook(s) pls...

Aflatoon
10-09-2018, 07:13 AM
If events are disabled, it would require manual code to do that.

stranno
10-09-2018, 07:47 AM
which codes do not run as a result of the disabled events?

post all the codes or workbook(s) pls...

p45cal
10-09-2018, 08:43 AM
1.Save the file with the read-only recommended option set? Perhaps with a password if you want.

2. Don't set applicationevents=false but use a different method to stop event-handlers' code operating, such as a global variable being set (eg a boolean EventBlocked variable) and each event-handler code starting with

If Not EventBlocked then
'the usual event code
End If
then set the boolean variable elsewhere. This means you'll be able to control any or all of the event handlers, even being more choosy by using more than one such boolean variable.

stranno
10-09-2018, 09:14 AM
1.Save the file with the read-only recommended option set? Perhaps with a password if you want.

2. Don't set applicationevents=false but use a different method to stop event-handlers' code operating, such as a global variable being set (eg a boolean EventBlocked variable) and each event-handler code starting with

If Not EventBlocked then
'the usual event code
End If
then set the boolean variable elsewhere. This means you'll be able to control any or all of the event handlers, even being more choosy by using more than one such boolean variable.

Thanks again p45cal. It's a lot of work (in my case) but I think it's the only solution.