Great Stuff.
Sub CommandButton1()
Dim lng As Long
On Error GoTo ErrorHandler
Application.EnableCancelKey = xlErrorHandler
MsgBox "This may take a long time: press ESC to cancel"
For lng = 1 To 1000000
' do something here
Next lng
Exit Sub
ErrorHandler:
If Err = 18 Then
If MsgBox("Do you want to stop?", vbYesNo, "Quit?") = vbYes Then
Application.StatusBar = True 'false
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
MsgBox "macro stopped"
End
Else
Resume
End If
End If
This is great and it works!
Again Thanks
Bookmarks