View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_5_] Jim Thomlinson[_5_] is offline
external usenet poster
 
Posts: 486
Default Hot key to stop a LOOP

Here is some quick code based on that link... Toss it into a command button
and give it a try. It resets the application settings you may have changed,
and also give you the option to resume the loop...

Private Sub CommandButton1_Click()
Dim lng As Long
On Error GoTo ErrorHandler
Application.EnableCancelKey = xlErrorHandler
For lng = 1 To 1000000

Next lng
Exit Sub
ErrorHandler:
If Err = 18 Then
If MsgBox("Do you want to stop?", vbYesNo, "Quit?") = vbYes Then
Application.StatusBar = False
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End
Else
Resume
End If
End If
End Sub
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

Here is the link... Sorry posted before I pasted... :-)

http://msdn.microsoft.com/library/de...HV03076682.asp
--
HTH...

Jim Thomlinson


"joopdog" wrote:


Is there away to stop a loop using a hot key, <esc or the <ctrl-break
key?

Any help would be appreciaited.


--
joopdog
------------------------------------------------------------------------
joopdog's Profile: http://www.excelforum.com/member.php...o&userid=31336
View this thread: http://www.excelforum.com/showthread...hreadid=510599