Reputation: 649
I have 3 toggle buttons as shown in Excel VBA. First I press continuous then it will be pressed and start running macro. During that if I need to press Emergency button I need to do :
step1: Switch off Continuous button
step2 : Switch on Emergency Button ( manual is irrelevent here)
Currently when I try to do this, Emergency Stop cannot be pressed until macro of continuous ends.
Upvotes: 1
Views: 489
Reputation: 149277
I use this most of the time when I trying to say, scrape data from the net.
Option Explicit
Dim boolStop As Boolean
'~~> Continuous button
Private Sub CommandButton1_Click()
CommandButton1.Enabled = False
boolStop = False
For i = 1 To 1000000000
For j = 1 To 1000000000
Debug.Print i
DoEvents
If boolStop = True Then
Msgbox "Operation Paused by the User"
CommandButton1.Enabled = True
Exit Sub
End If
Next j
Next i
End Sub
'~~> Emergency button
Private Sub CommandButton3_Click()
boolStop = True
End Sub
Upvotes: 2