• Hit any key to … (O2K SP3 (Excel))

    • This topic has 1 reply, 2 voices, and was last updated 18 years ago.
    Author
    Topic
    #442429

    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.

    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
    Viewing 0 reply threads
    Author
    Replies
    • #1064984

      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.

    Viewing 0 reply threads
    Reply To: Hit any key to … (O2K SP3 (Excel))

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: