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