Statement to execute code on “Break”

Glory

Well-known Member
Joined
Mar 16, 2011
Messages
640
I’d like to be able to execute some code when VBA enters “Break mode”. Is there a statement to accomplish this?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You could execute code through the Immediate window but other than that you are in *break* mode -- by definition code execution has been *interrupted*.
I’d like to be able to execute some code when VBA enters “Break mode”. Is there a statement to accomplish this?
 
Upvote 0
I'm thinking something like "on error".

I’ve got this macro that takes like five minutes to run. More importantly, it disables screenupdating using a windows API function (found here).
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
I want the user to be able to break the code without hopping into Excel’s VBE, if at all possible.

Nothing comes to mind?
 
Upvote 0
I allow the customer to interrupt a long running procedure through the use of a userform shown modeless. The userform has a 'cancel' button that, when clicked, sets a global boolean to true. The code checks the state of this variable "every so often" and if it sees it is true, the code gracefully stops.

You can see the above in action in the TM Directory Listing shareware product. Visit http://www.tushar-mehta.com/excel/software/dirlist/index.html

But, then, I am not a believer of messing with the customer's environment with APIs that disable screenpdating (or other such features). So I don't know if my solution will work for you.

I'm thinking something like "on error".

I’ve got this macro that takes like five minutes to run. More importantly, it disables screenupdating using a windows API function (found here).
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
I want the user to be able to break the code without hopping into Excel’s VBE, if at all possible.

Nothing comes to mind?
 
Upvote 0
The only reason I’m using the API is because I need to suppress “Now Printing” dialogue windows… otherwise hundreds of these would be appearing as the macro ran its course.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
Do you have any suggestions for suppressing these dialogues, that do not require disabling screenupdating (which is an admittedly dicey angle of attack)?
 
Upvote 0
Check if what I suggested works with the API you are using.
The only reason I’m using the API is because I need to suppress “Now Printing” dialogue windows… otherwise hundreds of these would be appearing as the macro ran its course.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
Do you have any suggestions for suppressing these dialogues, that do not require disabling screenupdating (which is an admittedly dicey angle of attack)?
 
Upvote 0
Your suggestion combined with an error handler did the trick. Needs the handler because setting the global boolean to exit the macro causes an error wherever the user triggered the hotkey that controls the exit command. Thanks for the suggestion.
 
Upvote 0
Your suggestion combined with an error handler did the trick. Needs the handler because setting the global boolean to exit the macro causes an error wherever the user triggered the hotkey that controls the exit command. Thanks for the suggestion.

:)
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,854
Members
452,948
Latest member
UsmanAli786

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