Start/Stop Macro Button

  • Thread starter Thread starter Paul987
  • Start date Start date
P

Paul987

I have a macro that runs continuously w/ a timer, however I would lik
to be able to start and stop it with a button. I can't seem to get th
Toggle Buttong to do this. Any help?
TIA
Pau
 
Seeing your Toggle Button's code would help. But in the meantime, here is
code using 2 buttons and a module-wide visible 'switch' you can start with
one button and stop with the other - but note, as written nothing to stop
person from hitting "Start..." button before time is up and starting it over,
giving themself more time. Note that this code will not compile/run because
"TimeIsUp" is undefined - I just used that as a placeholder.

Option Explicit
Dim StopTimer As Boolean

Sub Button1_Click()
TimeIsUp = False
'clicking this button starts the timed event
StopTimer = False
Do Until TimeIsUp Or StopTimer = True
'looping inside timer loop
'the "TimeIsUp" would be the conditions
'you've set up to indicate out of time
DoEvents
Loop
MsgBox "Time is up or you Stopped It"
End Sub

Sub Button2_Click()
'simply set the flag to True
StopTimer = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top