+ Reply to Thread
Results 1 to 2 of 2

Stop a loop

  1. #1
    Registered User
    Join Date
    02-05-2004
    Posts
    6

    Stop a loop

    Hi,

    I have a macro which simply pages through a number of sheets as in:

    Line1:
    Sheets("1").select
    Application.Wait Now + TimeValue("00:00:10")
    Sheets("2").select
    Application.Wait Now + TimeValue("00:00:10")
    Sheets("3").select
    Application.Wait Now + TimeValue("00:00:10")
    goto Line1

    What I would like to be able to do is to just press any key to stop the macro without getting the "code execution has been interrupted" message box. I can recall seeing other posts on this topic a while ago, but now that I need it, I can't locate them. Can anyone help?

    Thanks
    Mat

  2. #2
    Registered User
    Join Date
    10-25-2004
    Posts
    88
    Public Sub SomeMacro()

    On Error GoTo PROC_EXIT

    Application.EnableCancelKey = xlErrorHandler

    ' Code that possibly contains a Loop

    PROC_EXIT:
    Exit Sub

    End Sub


    Hitting ESC or Ctl-Break will interrupt the loop and transfer control to your error handler which tehn simplu exits the macro

+ 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