+ Reply to Thread
Results 1 to 6 of 6

Hot key to stop a LOOP

Hybrid View

  1. #1
    Registered User
    Join Date
    02-08-2006
    Posts
    4

    Hot key to stop a LOOP

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

    Any help would be appreciaited.

  2. #2
    John Keith
    Guest

    RE: Hot key to stop a LOOP

    Yep, use Ctrl-Break.

    Sometimes you might have to press it a time-or-two to get the key-press to
    register. It will give you the options to continue,end, debug, help.

    --
    Regards,
    John


    "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
    >
    >


  3. #3
    Jim Thomlinson
    Guest

    RE: Hot key to stop a LOOP

    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
    >
    >


  4. #4
    Jim Thomlinson
    Guest

    RE: 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
    > >
    > >


  5. #5
    Registered User
    Join Date
    02-08-2006
    Posts
    4

    Thanks

    Great Stuff.

    Sub CommandButton1()
    Dim lng As Long
        On Error GoTo ErrorHandler
        Application.EnableCancelKey = xlErrorHandler
        MsgBox "This may take a long time: press ESC to cancel"
        For lng = 1 To 1000000
            ' do something here
        Next lng
        Exit Sub
    ErrorHandler:
    If Err = 18 Then
        If MsgBox("Do you want to stop?", vbYesNo, "Quit?") = vbYes Then
            Application.StatusBar = True  'false
            Application.EnableEvents = True
            Application.Calculation = xlCalculationAutomatic
            MsgBox "macro stopped"
            End
        Else
            Resume
        End If
    End If
    This is great and it works!

    Again Thanks

  6. #6
    Jim Thomlinson
    Guest

    RE: Hot key to stop a LOOP

    Give this a look... It catches the escape key.
    --
    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
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1