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.


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.


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


The property Application.EnableCancelKey does not exist in PowerPoint.

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