Results 1 to 2 of 2
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Youngstown, Ohio, USA
    Posts
    705
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Hit any key to ... (O2K SP3 (Excel))

    I have a workbook_open procedure set up, but I want to insert a 'hit any key' or 'hit esc' check so the user can prevent the remainder of the autoexec code from running, ie open in maintenance mode vs run mode. I've tested application.onkey "{ESC"}, "subEscHit" but without success. When run, if Esc is not hit everything flows through as expected; if Esc is hit then I get a beep and then nothing else.

    <pre>Public EscHit As Integer

    Public Sub test()
    EscHit = 0
    Application.OnKey "{ESC}", "subEscHit"
    Application.StatusBar = "Testing ."
    For TestTimer = 1 To 10
    If EscHit = 1 Then GoTo Aborted
    Application.Wait (Now + TimeValue("0:00:01"))
    Application.StatusBar = Application.StatusBar & " ."
    Next
    GoTo NotAborted
    Aborted:
    MsgBox ("ESC key hit")
    GoTo Done
    NotAborted:
    MsgBox ("Finished without breaks")
    'Call other autoexec processes here
    Done:
    Application.StatusBar = False
    End Sub

    Public Sub subEscHit()
    EscHit = 1
    Debug.Print EscHit
    End Sub</pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Hit any key to ... (O2K SP3 (Excel))

    Your code works as expected when I try it.

    But you can simply hold down the Shift key while opening the workbook to suppress the execution of automatic macros.

Posting Permissions

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