Is there a way to interrupt a VBA code run?

User Name

Spammer
Joined
Aug 10, 2010
Messages
182
Hello

I'm writing a VBA program with multiple loops that tends to get hung up during the beta testing process. Is there a way to interrupt the code and jump to the vba window?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Press the Esc key on they keyboard. This will force-break your code.
 
Upvote 0
You can also try the Break key. On the laptop I use it is tied to the fn key so in my case:

fn + Break stops the macro and keeps my junk from melting. :)
 
Upvote 0
OK... great... thank you so much...

The ESC key doesn't work most of the time - in greys out the screen but that's about it. I think I've tried every key on the board but I'll try fn and fn + break. Thank you so much. I hate losing work and have put up with this state of affairs for far too long.
 
Upvote 0
Whenever I am building an app I have a boolean variable in there call DebugFlag and at the begining of any intensive loops or crazy stuff I have a simple If DebugFlag then blah blah to limit the transactions it will perform. I use it throughout the code all over the place to really restrict what I am doing, also to print out SQL calls and various data points to the immediate window.

At the start of the code I simply have DebugFlag = True or False depending what I am doing

Just a suggestion :).
 
Upvote 0
Thanks... I've used something like this with various results. The problem is it's hard to come up with a good set of debug logic for the problem I'm working on. But I think you're right. If KillLoop = 100000000 then step out. Not a bad suggestion.
 
Upvote 0
Depending on your keyboard, I guess - but CTRL+Break always seems to cut the code run for me. And I use it a lot!!!! :laugh:

Cheers,
Gino
 
Upvote 0
Adding a DoEvents statement to your loops also helps the system recognise the keyboard.

If you do that, a button whose click event just peforms an End should stop a loop cold.
 
Upvote 0
Depending on your keyboard, I guess - but CTRL+Break always seems to cut the code run for me. And I use it a lot!!!! :laugh:

Cheers,
Gino

I have found that with Excel 2010, one has to now use "Ctrl+Shift+Break" - you may want to make a note of that Gino, to use when you upgrade to Excel 2010 or later... unless Microsoft remedies it.
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,319
Members
452,905
Latest member
deadwings

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