Results 1 to 6 of 6

Thread: What is an User interrupt handling in VBA of Excel?

  1. #1
    Join Date
    May 2009
    Posts
    543

    What is an User interrupt handling in VBA of Excel?

    Hello friends,
    I have recently started with the Visual Basic for Applications in an Excel. I want to know about an interrupt handling that takes place in VBA. So thought that there would be someone hanging out there who can help me.!! Please tell me what is an User interrupt handling in VBA of Excel? Since I don't know much about it, please provide information in details.

  2. #2
    Join Date
    Apr 2008
    Posts
    4,088

    Re: What is an User interrupt handling in VBA of Excel?

    When you add code handling errors in your macros to Visual Basic applications, you discover that the same mistakes are treated repeatedly. You can reduce the size of your code and effort required to write code by writing a few procedures that your code error handling can call to handle situations common error. A user can interrupt a Visual Basic for applications by pressing Command-period. It is possible to disable interrupts for procedures in your applications finished. However, if you do not disable the user interrupts the procedure is complete, you can ensure that your procedure is notified when an interruption occurred so that it can close files, disconnect shared resources or restore modified variables before returning control to the application to the user.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,139

    Re: What is an User interrupt handling in VBA of Excel?

    You can trap user interrupts in your procedures by setting the property EnableCancelKey on xlErrorHandler. When this property is set, all interrupts generates an error number 18, which can be intercepted using an On Error executing. You can handle the error to stop the procedure and exit the program. If the Resume statement is used in the procedure following a runtime error intercepted, the interrupt is ignored.

  4. #4
    Join Date
    May 2008
    Posts
    3,316

    Re: What is an User interrupt handling in VBA of Excel?

    It is also possible for you to ignore user interrupts completely by setting the property EnableCancelKey on xlDisabled. In this report, Microsoft Excel for Mac ignores all attempts by the user to interrupt the process running. To restore the default interrupt processing, change the property setting EnableCancelKey to xlInterrupt. To prevent a procedure permanently disable interrupts from the user, Excel for Mac always restore the default property EnableCancelKey xlInterrupt whenever the procedure completes execution. To ensure that interrupts are handled correctly in your code must explicitly disable or trap the interrupts each time the procedure is executed.

  5. #5
    Join Date
    Jan 2008
    Posts
    3,755

    Re: What is an User interrupt handling in VBA of Excel?

    You must also keep in mind that interrupt handler can only be used for each procedure and the same manager is used for all errors encountered by implementing the scheme. If you run the macro ProcessData and then quickly press CTRL + Break, a message box asking if you want to stop processing records appears. If you click Yes, another message box with "User interrupt occurred" appears. If you click OK in the message box, the macro ends. If you click No in the first message box, the macro continues. The Resume statement resumes code execution after a routine error handling is complete.

  6. #6
    Join Date
    May 2008
    Posts
    390

    Re: What is an User interrupt handling in VBA of Excel?

    The following example demonstrates a procedure that requires a long period of time to complete. If a user interrupts the procedure, an error is caught. The interruption of the user first confirms that the proceedings must indeed be interrupted and then exit the procedure smoothly. So have a look at an example :
    Code:
    Sub ProcessData ()
           'Set up a user interrupt trapping as a run-time error
           On Error GoTo UserInterrupt
           Application.EnableCancelKey = xlErrorHandler
    
           'Start a long duration task
           For x = 1 to 1000000
              For y = 1 to 10
              Next y
           Next x
    
           Exit Sub
        UserInterrupt:
           If Err = 18 Then
              If MsgBox ( "Stop processing records?", VbYesNo) = vbNo Then
                 'Keep running at the point procedure was interrupted
                 Resume
              Else
                 'Handle other errors that occur
                 MsgBox Error (Err)
              End If
           End If
        End Sub

Similar Threads

  1. Create a user control form in Excel 2010
    By --MasseySian-- in forum Software Development
    Replies: 3
    Last Post: 06-09-2012, 07:03 PM
  2. Need help to create a login user form in Microsoft Excel
    By Henriksen in forum MS Office Support
    Replies: 2
    Last Post: 23-02-2012, 06:04 PM
  3. User Add Data Pop up box in Microsoft Excel
    By Tur^turro in forum MS Office Support
    Replies: 3
    Last Post: 11-01-2012, 04:51 PM
  4. cannot open excel after change user name
    By bunnie in forum Windows Software
    Replies: 1
    Last Post: 27-12-2009, 06:40 PM
  5. Create user defined functions in Excel 2007
    By AbhayD in forum Windows Software
    Replies: 3
    Last Post: 24-06-2009, 07:05 PM

Tags for this Thread

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
  •  
Page generated in 1,711,623,452.11685 seconds with 17 queries