Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default 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.



  #2   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default 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..


  #3   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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.




  #4   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming
external usenet poster
 
Posts: 449
Default 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.




  #5   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Stopping a userform subroutine

thanks will give it a go




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call a subroutine using variable subroutine name dhstein Excel Discussion (Misc queries) 3 July 26th 09 08:28 PM
Stopping a userform subroutine teepee[_3_] Excel Discussion (Misc queries) 5 January 13th 09 01:10 AM
How To Quit Subroutine from a called subroutine Rich J[_2_] Excel Programming 5 February 20th 07 06:48 PM
stopping userform resize on minimize hughie Excel Programming 4 January 9th 07 12:25 PM
How to make userform disappear while called subroutine is running Cornelia Excel Programming 2 June 16th 06 10:47 PM


All times are GMT +1. The time now is 11:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"