S
scott56hannah
Hi,
I would like to stop / pause a macro that is running using a Pause button on
a form...
Some of the code is copied below....
Currently when you start the macro it continues through until then end even
if the pause button is selected...it seems only to recognise the pause button
when it gets to the end of the processing....
Is there anyway to get the Pause button recognised while the macro is
running ?
Private Sub PauseButton_Click()
If UserForm1.PauseButton.Caption = "Pause" Then
UserForm1.PauseButton.Caption = "Continue"
MsgBox "Button was Paused and is now Continue"
Exit Sub
End If
If UserForm1.PauseButton.Caption = "Continue" Then
UserForm1.PauseButton.Caption = "Pause"
MsgBox "Button was Continue and is now Pause"
Call ProcessEvents
End If
End Sub
Private Sub StartButton_Click()
intLoopCount = 1
UserForm1.PauseButton.Caption = "Pause"
Call ProcessEvents
End Sub
Private Sub UserForm_Activate()
UserForm1.LoopCountLabel.Caption = "Loop Count " & intLoopCount & "
Display Number "
End Sub
Sub ProcessEvents()
'This routine will process events and when complete needs to pause and
wait for user input
Dim i As Long
Do While intLoopCount < 10
i = 0
blnAllowPauseContinueEvent = False
Do While i < (intLoopCount * 500)
UserForm1.LoopCountLabel.Caption = "Loop Count " & intLoopCount
& " Display Number " & i
UserForm1.Repaint
i = i + 1
Loop
intLoopCount = intLoopCount + 1
Loop
End Sub
Thanks
Scott
I would like to stop / pause a macro that is running using a Pause button on
a form...
Some of the code is copied below....
Currently when you start the macro it continues through until then end even
if the pause button is selected...it seems only to recognise the pause button
when it gets to the end of the processing....
Is there anyway to get the Pause button recognised while the macro is
running ?
Private Sub PauseButton_Click()
If UserForm1.PauseButton.Caption = "Pause" Then
UserForm1.PauseButton.Caption = "Continue"
MsgBox "Button was Paused and is now Continue"
Exit Sub
End If
If UserForm1.PauseButton.Caption = "Continue" Then
UserForm1.PauseButton.Caption = "Pause"
MsgBox "Button was Continue and is now Pause"
Call ProcessEvents
End If
End Sub
Private Sub StartButton_Click()
intLoopCount = 1
UserForm1.PauseButton.Caption = "Pause"
Call ProcessEvents
End Sub
Private Sub UserForm_Activate()
UserForm1.LoopCountLabel.Caption = "Loop Count " & intLoopCount & "
Display Number "
End Sub
Sub ProcessEvents()
'This routine will process events and when complete needs to pause and
wait for user input
Dim i As Long
Do While intLoopCount < 10
i = 0
blnAllowPauseContinueEvent = False
Do While i < (intLoopCount * 500)
UserForm1.LoopCountLabel.Caption = "Loop Count " & intLoopCount
& " Display Number " & i
UserForm1.Repaint
i = i + 1
Loop
intLoopCount = intLoopCount + 1
Loop
End Sub
Thanks
Scott