VBA Escape key not behaving as expected

tmgr3788

New Member
Joined
Sep 1, 2015
Messages
1
Hi all,

I've had a search around and found variations of this question across the web, but none answered.

My understanding is that that escape key should immediately stop a macro, raising error code 18 and have previously found this to be the case.

I'm now using a different computer (Windows 8, Excel 2013) and it doesn't behave the same way.

Example:
Code:
Sub main()

Application.StatusBar = "Waiting 1"
Application.Wait (Now + TimeValue("00:00:10"))
Application.StatusBar = "Waiting 2"
Application.Wait (Now + TimeValue("00:00:10"))
Application.StatusBar = "Done waiting"


MsgBox ("Message Box")


End Sub

Pressing Esc while the status bar says "Waiting 1" should end the macro with an error, the status bar should stay the same and I should have the opportunity to enter debug mode.
When I do this the status bar instead immediately changes to "Done waiting", no error, no message box.

Example 2:
Code:
Sub main()

Application.StatusBar = "Waiting 1"
Application.Wait (Now + TimeValue("00:00:10"))
MsgBox ("Message Box")
Application.StatusBar = "Waiting 2"
Application.Wait (Now + TimeValue("00:00:10"))
Application.StatusBar = "Done waiting"


End Sub




Pressing escape during Waiting 1 on this changes the status bar immediately to Waiting 2, then 10 seconds later to Done waiting. No errors or message boxes.

Running both without pressing escape runs as expected with waits and the message box popping up.

Ctrl+Break works correctly in both of these cases, but as I don't currently have a keyboard with a break key, it's a pain using the on-screen keyboard to abort auto-running macros quickly.

Escape also does not trigger the error handler when using Application.EnableCancelKey = xlErrorHandler

It looks like escape is causing vba to skip certain commands (waits), run others (status bar updates), and be interrupted by some others (message box).

Any ideas on what's going on?
Could there be a setting that has been changed on this computer?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,222,617
Messages
6,167,079
Members
452,094
Latest member
Roberto Saveru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top