简体   繁体   中英

Press other button2 when button 1 is pressed EXCEL VBA

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM