Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Feb 2004
    Location
    Hatboro, Pennsylvania, USA
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Intercepting ESC-key (97,2k)

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

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Intercepting ESC-key (97,2k)

    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>


  3. #3
    Lounger
    Join Date
    Feb 2004
    Location
    Hatboro, Pennsylvania, USA
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks: Intercepting ESC-key (97,2k)

    Thanks for the help!
    ~~~Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •