Pausing a macro during execution

S

Scott

I have a macro that moves some objects around on a spreadsheet to
simulate a process. It has a start and stop time it is set to run.
What I would like to do is be able to hit the ESC or some other hey
while the macro(s) are processing, it would stop where it is at and
then if I hit the button again it would continue. I dont want the VB
message box that says "code execution has been interrupted" to pop up
and take me to the VB editor.
I just want a simple pause. I am thinking there has to be some way to
look for key stokes and then if a certian one is encountered be able
to pause until it is hit again.

Thanks
Scott RIddle
 
J

Jim Thomlinson

This is not exactly what you are looking for but it is close. Hitting the Esc
key will pause execution...

Public Sub PauseMacroIsh()
Dim lng As Long

Application.EnableCancelKey = xlErrorHandler
On Error GoTo ErrorCleanUp
For lng = 1 To 100000
Application.StatusBar = lng
Next lng

ErrorCleanUp:
If Err = 18 Then
MsgBox "macro has been paused"
Resume
Else
Application.StatusBar = False
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top