ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   EnableEvents (https://www.excelbanter.com/excel-programming/387385-enableevents.html)

clara

EnableEvents
 
Hi all,

EnableEvents = false and EnableEvents = true need to be paired ? Similiar
issue are ScreenUpdating,DisplayAlerts.

Clara
--
thank you so much for your help

Norman Jones

EnableEvents
 
Hi Clara

EnableEvents = false and EnableEvents = true need to be paired ? Similiar
issue are ScreenUpdating,DisplayAlerts.


Normally, yes!

More generally, changes which are made to application
settings should normally be reversed by your code when
no longer required.

It is often therefore, advisable to restore application settings
to their previous state in an error handler; in this way any
error in the code will not prevent the desired restoration of
the previous settings. An example might be:

'================
Public Sub Tester()
Dim CalcMode As Long

On Error GoTo XIT
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

'Your code

XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub
'<<================


---
Regards,
Norman



clara

EnableEvents
 
Hi Norman, thank you very much!

Clara
--
thank you so much for your help


"Norman Jones" wrote:

Hi Clara

EnableEvents = false and EnableEvents = true need to be paired ? Similiar
issue are ScreenUpdating,DisplayAlerts.


Normally, yes!

More generally, changes which are made to application
settings should normally be reversed by your code when
no longer required.

It is often therefore, advisable to restore application settings
to their previous state in an error handler; in this way any
error in the code will not prevent the desired restoration of
the previous settings. An example might be:

'================
Public Sub Tester()
Dim CalcMode As Long

On Error GoTo XIT
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

'Your code

XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub
'<<================


---
Regards,
Norman





All times are GMT +1. The time now is 03:34 PM.

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