Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Stop Macro button in Excel VB

The problem is most likely that you have not declared the StopNow
variable. If you don't declare the variable, VBA will create it
within the procedure in which it finds it. Therefore, you have
two completely variables named StopNow, one in each procedure.

The solution is to declare a global variable above and outside of
any procedu

Public StopNow As Boolean

If you had an "Option Explicit" statement at the top of the
module, as you should, the cause of the problem would be obvious
because you would get a "Variable Not Defined" compiler error.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"grahammal"
wrote in
message
...

Sub Button1_Click()
StopNow = False
For i = 1 To 30000
Range("A1").Value = i
' DoEvents
If StopNow Then Exit For
Next i
End Sub


Sub Button2_Click()
StopNow = True
End Sub

I have tried the above idea to stop a macro continuing to run
but it
dos'nt work for me.
I generated the 2 buttons, copied the relevent code to the
buttons and
pressed the first button.
I can see the value clocking up in cell A1 but you can't press
the
second button to stop the macro from running???
Am I being stupid or have I missed something?


--
grahammal
------------------------------------------------------------------------
grahammal's Profile:
http://www.excelforum.com/member.php...o&userid=20336
View this thread:
http://www.excelforum.com/showthread...hreadid=477826



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
Stop Undo Button from working in Excel 2007 after a Save Jugglertwo Excel Discussion (Misc queries) 1 October 15th 09 09:19 PM
Start/Stop Macro Button Paul987 Excel Discussion (Misc queries) 1 July 10th 06 05:14 PM
Macro Record Stop Button Patrick Simonds Excel Discussion (Misc queries) 2 July 31st 05 06:11 PM
Excel Stop Recording Button Disappeared WeeSpeck Excel Discussion (Misc queries) 4 July 17th 05 01:23 PM
Can I programmatically simulate clicking the 'stop macro' button in the VBE? Alan Excel Programming 9 January 24th 05 01:15 AM


All times are GMT +1. The time now is 07:58 PM.

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"