Application.EnableCancelKey

It is possible to interrupt a macro before it has finished by pressing Esc or (Ctrl + Break) or (Command + Period).
Changing should not be changed because infinite loops and non terminating code cannot be interrupted.


Excel

The EnableCancelKey property will be automatically reset to xlInterrupt at the end of your macro.
It is a good idea to switch it back manually though as soon as possible.

Application.EnableCancelKey = xlEnableCancelKey.xlDisabled 
'add your code
Application.EnableCancelKey = xlEnableCancelKey.xlInterrupt

If you set this property to xlErrorHandler but your error handler returns using a Resume statement, the macro code run indefinitely.


Word

Application.EnableCancelKey = wdEnableCancelKey.wdCancelDisabled 
'add your code
Application.EnableCancelKey = wdEnableCancelKey.wdCancelInterrupt

PowerPoint

The property Application.EnableCancelKey does not exist in PowerPoint.



© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext