![]() |
Stopping a userform subroutine
I have a looping sub triggered by a userform button. I'm trying to figure
out how to stop that same sub with another button on the same userform. It's kind of ugly just hitting escape. Any ideas? Is there a standard way? I tried 'loop until' and making the second button achieve the 'until' condition but that didn't work - I can't trigger the second button at all. |
Stopping a userform subroutine
Hi
If one sub is running behind the userform, you can not run another sub. Post the macro, so we can find a solution. Regards, Per On 11 Jan., 23:40, "teepee" wrote: I have a looping *sub *triggered by a userform button. I'm trying to figure out how to stop that same sub with another button on the same userform. It's kind of ugly just hitting escape. Any *ideas? Is there a standard way? I tried 'loop until' and making the second button achieve the 'until' condition but that didn't work - I can't trigger the second button at all.. |
Stopping a userform subroutine
There are a couple of ways to stop a macro once it begins, but none of them
are really desirable. One, of course, is Ctrl + Alt + Delete, that's the "When all else fails" one. Another is Ctrl + Break, which is mostly used to halt a macro for debugging or when a continuous loop is accidentally initiated. Then there are the designed breaks like using a message box (MsgBox) function to temporarily halt a macro without going into break mode, or using "Stop" in your code to pause the macro in edit mode. But generally speaking, once you start a macro it will run to completion unless you use one or more of the above. "teepee" wrote: I have a looping sub triggered by a userform button. I'm trying to figure out how to stop that same sub with another button on the same userform. It's kind of ugly just hitting escape. Any ideas? Is there a standard way? I tried 'loop until' and making the second button achieve the 'until' condition but that didn't work - I can't trigger the second button at all. |
Stopping a userform subroutine
Hi
Userform with Commandbutton1 (start) and Commandbuton2 (stop): Option Explicit Dim Stopit As Boolean Private Sub CommandButton1_Click() Dim i As Long, J As Long Stopit = False For i = 1 To 1000000 For J = 1 To 10000 'just spending time here ;-) Next DoEvents If Stopit = True Then Exit Sub Me.Caption = i Next End Sub Private Sub CommandButton2_Click() Stopit = True End Sub Trick here is "DoEvents" which roughly means "listen to the operating system before you continue". HTH. Best wishes Harald "teepee" wrote in message ... I have a looping sub triggered by a userform button. I'm trying to figure out how to stop that same sub with another button on the same userform. It's kind of ugly just hitting escape. Any ideas? Is there a standard way? I tried 'loop until' and making the second button achieve the 'until' condition but that didn't work - I can't trigger the second button at all. |
Stopping a userform subroutine
thanks will give it a go
|
All times are GMT +1. The time now is 07:24 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com