按下按钮1 EXCEL VBA时按其他按钮2

时间:2013-12-12 14:07:27

标签: vba excel-vba user-interface excel

我有3个切换按钮,如Excel VBA中所示。首先我按连续然后按下它并开始运行宏。在此期间,如果我需要按紧急按钮,我需要这样做:

步骤1:关闭连续按钮

步骤2:打开紧急按钮 (手册在这里无关紧要) Forget about manual button

目前,当我尝试这样做时,在连续的宏结束之前,无法按下紧急停止

1 个答案:

答案 0 :(得分:2)

当我试图说,从网上抓取数据时,我大部分时间都会使用它。

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