Thread: stop a macro
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
alvin Kuiper alvin Kuiper is offline
external usenet poster
 
Posts: 175
Default stop a macro

Thanks
Alvin


"AnExpertNovice" wrote:

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


--
My handle should tell you enough about me. I am not an MVP, expert, guru,
etc. but I do like to help.


"alvin Kuiper" wrote in message
...
Hi
Is there a way how i can stop a macro
maybe by a commandbutton

reagrds
Alvin