How can I intercept the ESC-key during a procedure?
How can I intercept the ESC-key during a procedure?

This month, every Windows Secrets subscriber can download a one-chapter excerpt of Windows 7: The Missing Manual.Windows 7: The Missing Manual provides valuable information to help you overcome these difficulties in learning a new operating system. Subscribe today to download your free excerpt.
Here is some example code. It just does a very long loop. If ESC is pressed it stops, giving status and asking if you want to continue or quit. if continue it resumes, if quit it displays a message and ends
HTH,
Steve
<pre>Sub Looptest()
Application.EnableCancelKey = xlErrorHandler
On Error GoTo ErrHandler
Dim x As Long
Dim y As Long
Dim lContinue As Long
y = 100000000
For x = 1 To y Step 1
Next
Application.EnableCancelKey = xlInterrupt
Exit Sub
ErrHandler:
If Err.Number = 18 Then
lContinue = MsgBox(prompt:=Format(x / y, "0.0%") & _
" complete" & vbCrLf & _
"Do you want to Continue (YES)?" & vbCrLf & _
"Do you want to QUIT? [Click NO]", _
Buttons:=vbYesNo)
If lContinue = vbYes Then
Resume
Else
Application.EnableCancelKey = xlInterrupt
MsgBox ("Program ended at your request")
Exit Sub
End If
End If
Application.EnableCancelKey = xlInterrupt
End Sub</pre>
Thanks for the help!
~~~Paul