VBA-Programmierung in Microsoft Excel

Tutorial: Excel-Beispiele

VBA-Begriff: Beispiel zur EnableCancelKey-Eigenschaft

In diesem Beispiel wird gezeigt, wie mit der EnableCancelKey-Eigenschaft eine benutzerdefinierte Abbruchbehandlung eingerichtet werden kann.

On Error GoTo handleCancel
Application.EnableCancelKey = xlErrorHandler
MsgBox "This may take a long time: press ESC to cancel"
For x = 1 To 1000000    ' Do something 1,000,000 times (long!)
    ' do something here
Next x
handleCancel:
If Err = 18 Then
    MsgBox "You cancelled"
End If