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.
|