Hi all,
I am working on a workbook to do some updates automatically when the workbook opens, and I wanted to add a 20 second period to allow the user to abort the automation... However the enable cancel key method does not send the code to the error handler. Instead as the program is counting down, pressing escape seems to just bypass the one second application.wait and continues through the countdown.
Any idea how I can get the automation to actually stop when escape is pressed? Thanks!
I am working on a workbook to do some updates automatically when the workbook opens, and I wanted to add a 20 second period to allow the user to abort the automation... However the enable cancel key method does not send the code to the error handler. Instead as the program is counting down, pressing escape seems to just bypass the one second application.wait and continues through the countdown.
Any idea how I can get the automation to actually stop when escape is pressed? Thanks!
VBA Code:
Private Sub Workbook_Open()
'setup cancel key press
On Error GoTo xExit
Application.EnableCancelKey = xlErrorHandler
'notify user the application will wait for 10 second before running... press escape to cancel...
tmp = 20
For i = 0 To tmp - 1
Application.StatusBar = "Automation waking up... " & tmp - i & " seconds to launch... Press <escape> to abort the routine."
Application.Wait (Now + TimeValue("0:00:01"))
Next
'call routines for automation
Application.StatusBar = "Beginning automation..."
AutoOpened = True
Update_All
'exit sub
Exit Sub
'go here for error or escape key
xExit:
If Err.Number = 18 Then
MsgBox "Automatic update routine cancelled."""
End If
End Sub