How to interrupt a VBA macro stuck in an InputBox loop?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,532
Office Version
  1. 365
Platform
  1. Windows
I can't post the exact code because its stuck in an InputBox loop. This is close to what it is. I mistakenly put the IsNumeric right after the InputBox, which catches both Cancel so there is no way to exit. How can I interrupt it? Thanks

VBA Code:
Do
  vReply = InputBox(Time & " " & LastAction & vbCrLf & vbCrLf & Prompt, MyName, , 11000, 7000)
  'Cancel returns "", but so does "", so confirm both
  If Not IsNumric(vReply) Then GoTo BadInput

  . . .
 
BadInput:
  MsgBox "Invalid data", vbOKOnly, MyName
Continue:
Loop
 
Is the time wasted stuck in a loop waiting for a response that works better than just reevaluating the code after the restart?
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Well you can lose the last edits or stay stuck in an infinate loop where you can't do anything.
Apparently so. Is this yet another failure of the Surface Book or of Excel VBA or of Win 10? It seems to me that on my old ThinkPad running XP I was able to interrupt macros in loops like this.
 
Upvote 0
Is the time wasted stuck in a loop waiting for a response that works better than just reevaluating the code after the restart?
I wasn't just sitting here picking my nose. I do have other things to do. And I was hoping to find a solution in case I do it again, which I probably will.
 
Upvote 0
I wasn't just sitting here picking my nose. I do have other things to do. And I was hoping to find a solution in case I do it again, which I probably will.
I wasn't suggesting that you were picking your nose. Based on my personal experience, I have to tell you, that is not going to help the situation.

If it were me, I would bite the bullet and just get it back to where you can change your mistake in the code that you mentioned. Then in your leisure time (Not picking your nose) try to google how to get the 'Break' to work so that you have that info for future reference.
 
Upvote 0
My laptop doesn't have a pause or break key either, but holding down the ESC key for a few seconds (rather than tapping it) brought up the End/Debug/etc. prompt which allowed me to stop the macro.

Another option, if that doesn't work, might be to bring up the on-screen keyboard - hopefully yours has a pause or break key there. (Mine has pause, but no break.)
 
Upvote 0
A good alternative I just tried is downloading Microsoft PowerToys from the Microsoft Store (it's free).

Once installed, in PowerToys go to Keyboard Manager.
Click 'Remap a key'
Click the + button to add a new mapping
Beneath 'Physical key' click Type and then tap a key you want to map. For me, I picked the backwards apostrophe key in the top left as I never use it.
Beneath 'Mapped to', click the drop-down and first select "Ctrl (Left)", then select "Break" from the second drop-down that appears.
Click Ok
Click Continue anyway

Go back to excel and tap the key you mapped and it should act just like CTRL+Break. You can then go back into PowerToys and delete the custom mapping. (Or keep it!)

Hope that helps.
 
Upvote 0
My laptop doesn't have a pause or break key either, but holding down the ESC key for a few seconds (rather than tapping it) brought up the End/Debug/etc. prompt which allowed me to stop the macro.
Did you do this with the sample code I posted here? I just tried it. When I press and hold Esc, it immediately puts up my "Invalid input" MsgBox. The code gets a null string from InputBox in response to Esc. Holding it longer does nothing.

Another option, if that doesn't work, might be to bring up the on-screen keyboard - hopefully yours has a pause or break key there. (Mine has pause, but no break.)
That's an interesting option. I never knew about that. It can be brought up using Ctrl+Win+o. Here's what mine looks like:

1667024961155.png


I do have a Pause button. Clicking it makes a soft clicking sounds, but no action on the macro code. I also tried Ctrl+Pause, Win+Pause, etc.

But thanks for showing me that keyboard.
 
Upvote 0
My laptop doesn't have a pause or break key either, but holding down the ESC key for a few seconds (rather than tapping it) brought up the End/Debug/etc. prompt which allowed me to stop the macro.
Holding down the escape key worked fine on my laptop when I tried to replicate the scenario.
 
Upvote 0
A good alternative I just tried is downloading Microsoft PowerToys from the Microsoft Store (it's free).

Once installed, in PowerToys go to Keyboard Manager.
Click 'Remap a key'
Click the + button to add a new mapping
Beneath 'Physical key' click Type and then tap a key you want to map. For me, I picked the backwards apostrophe key in the top left as I never use it.
Beneath 'Mapped to', click the drop-down and first select "Ctrl (Left)", then select "Break" from the second drop-down that appears.
Click Ok
Click Continue anyway

Go back to excel and tap the key you mapped and it should act just like CTRL+Break. You can then go back into PowerToys and delete the custom mapping. (Or keep it!)

Hope that helps.
I found PowerToys here:


I have Win 10 (19044) x64 so it should work.

It says it installs several runtime environments. I hope none of that will affect anything I am doing with Edge. I don't use .NET or C++.

1667025949731.png
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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