stop a macro

  • Thread starter Thread starter Guest
  • Start date Start date
There are many ways to stop a macro.
on a PC
Ctrl-Break
Ctrl-C
power button (ok some are more drastic than others. ;)

In case you are asking how to allow a user to stop a macro by pressing the
Control key.

(warning, this code was reduced to a "minimal" state and may not actually
since variables may not be declared, orphaned lines might still exist, etc.


Public Const VK_CONTROL = &H11
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As
Integer

Sub LoopingRoutine()
Dim intResponse As Integer
On Error GoTo ErrorRoutine
Do Until 0 = 1
If GetAsyncKeyState(VK_CONTROL) Then
intResponse = MsgBox(Prompt:="Did you wish to stop looping?",
Buttons:=vbYesNo)
If intResponse = vbYes Then
Exit Do
End If
End If
Loop
ExitRoutine:
Exit Sub
ErrorRoutine:
Resume ExitRoutine
End Sub
 
Thanks
Alvin


AnExpertNovice said:
There are many ways to stop a macro.
on a PC
Ctrl-Break
Ctrl-C
power button (ok some are more drastic than others. ;)

In case you are asking how to allow a user to stop a macro by pressing the
Control key.

(warning, this code was reduced to a "minimal" state and may not actually
since variables may not be declared, orphaned lines might still exist, etc.


Public Const VK_CONTROL = &H11
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As
Integer

Sub LoopingRoutine()
Dim intResponse As Integer
On Error GoTo ErrorRoutine
Do Until 0 = 1
If GetAsyncKeyState(VK_CONTROL) Then
intResponse = MsgBox(Prompt:="Did you wish to stop looping?",
Buttons:=vbYesNo)
If intResponse = vbYes Then
Exit Do
End If
End If
Loop
ExitRoutine:
Exit Sub
ErrorRoutine:
Resume ExitRoutine
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

Back
Top