Guest User

Untitled

a guest
Feb 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. Application.EnableCancelKey = 2
  2. ?Application.EnableCancelKey
  3. 1
  4.  
  5. Sub Test1()
  6.  
  7. Debug.Print " Before execution result : " & Application.EnableCancelKey
  8.  
  9. On Error GoTo handleCancel
  10. Application.EnableCancelKey = 2 'xlErrorHandler
  11. Debug.Print " Regular execution result : " & Application.EnableCancelKey
  12.  
  13. For x = 1 To 10000 ' Do something 1,000,000 times (long!)
  14. Debug.Print "Test"
  15. Next x
  16.  
  17. handleCancel:
  18. If Err = 18 Then
  19. Debug.Print "Aborted macro result : " & Application.EnableCancelKey
  20. MsgBox "You cancelled"
  21. End If
  22.  
  23. End Sub
  24.  
  25. Sub test2()
  26.  
  27. On Error GoTo theEnd
  28. Application.EnableCancelKey = 2
  29. Debug.Print Application.EnableCancelKey
  30.  
  31. theEnd:
  32. End Sub
Add Comment
Please, Sign In to add comment