Private Sub CommandButton1_Click()
Dim i As Long
CommandButton1.Caption = "中止"
For i = 1 To Rows.Count
Cells(i, 1) = i
Next i
CommandButton1.Caption = "実行"
End Sub
Private Sub CommandButton1_Click()
Dim i As Long
CommandButton1.Caption = "中止"
DoEvents
For i = 1 To Rows.Count
Cells(i, 1) = i
Next i
CommandButton1.Caption = "実行"
End Sub
Dim StopFlag As Boolean
Private Sub CommandButton1_Click()
Dim i As Long
Select Case CommandButton1.Caption
Case "実行"
CommandButton1.Caption = "中止"
Label1.Caption = "[中止]ボタンで中止します"
DoEvents
For i = 1 To Rows.Count
Cells(i, 1) = i
DoEvents
If StopFlag = True Then Exit For
Next i
CommandButton1.Caption = "実行"
Label1.Caption = ""
StopFlag = False
Case "中止"
If MsgBox("中止しますか?", vbYesNo) = vbYes Then StopFlag = True
End Select
End Sub