LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Stop / Pause a Macro using Pause button

Paul,

Thanks for that.....I followed that approach and now have it working as needed

Scott

" wrote:

Hi
1. In your normal code module declare this public variable at the top

Public StopIt As Boolean

2. Change ProcessEvents macro to this

Sub ProcessEvents()
'This routine will process events and when complete needs to pause and
wait for user input
Dim i As Long
StopIt = False
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
If StopIt Then Exit Do
DoEvents
Loop
intloopCount = intloopCount + 1
If StopIt Then Exit Do
DoEvents
Loop
End Sub

3. Change PauseButton_Click to this

Private Sub PauseButton_Click()
If UserForm1.PauseButton.Caption = "Pause" Then
UserForm1.PauseButton.Caption = "Continue"
MsgBox "Button was Paused and is now Continue"
StopIt = True
Exit Sub
End If
If UserForm1.PauseButton.Caption = "Continue" Then
UserForm1.PauseButton.Caption = "Pause"
MsgBox "Button was Continue and is now Pause"
StopIt = False
Call ProcessEvents
End If
End Sub

regards
Paul

On Jun 26, 11:55 pm, scott56hannah
wrote:
Yes....and it did not operate as needed....I still cannot get the Pause
button to function or respond while the macro is running...which is exactly
what I want to pause...

Thanks



"Bob Phillips" wrote:
Did you try the answer that you got at VBAExpress?


--
__________________________________
HTH


Bob


"scott56hannah" wrote in message
...
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- Hide quoted text -


- Show quoted text -



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I pause a macro? Dave H Excel Discussion (Misc queries) 5 May 3rd 08 04:53 PM
Pause a Macro MESTRELLA29 Excel Programming 1 July 3rd 07 08:22 PM
Pause a Macro? Jimbo Excel Programming 2 October 14th 04 04:21 AM
Pause macro, add form button to sheet, continue macro when button clicked! Flystar[_15_] Excel Programming 1 May 26th 04 09:45 AM
How to Pause or Stop a running Macro jfeka[_2_] Excel Programming 0 July 17th 03 11:14 PM


All times are GMT +1. The time now is 03:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"