Go Back   TechArena Community > Software > Windows Software
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



What is an User interrupt handling in VBA of Excel?

Windows Software


Reply
 
Thread Tools Search this Thread
  #1  
Old 11-03-2010
Member
 
Join Date: May 2009
Posts: 532
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.

Reply With Quote
  #2  
Old 11-03-2010
Member
 
Join Date: Apr 2008
Posts: 4,098
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.
__________________
Ram requirement for various OS
Reply With Quote
  #3  
Old 11-03-2010
Member
 
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.
Reply With Quote
  #4  
Old 11-03-2010
Member
 
Join Date: May 2008
Posts: 3,317
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.
Reply With Quote
  #5  
Old 11-03-2010
Member
 
Join Date: Jan 2008
Posts: 3,759
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.
Reply With Quote
  #6  
Old 11-03-2010
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Windows Software
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is an User interrupt handling in VBA of Excel?"
Thread Thread Starter Forum Replies Last Post
Create a user control form in Excel 2010 --MasseySian-- Software Development 3 06-09-2012 07:03 PM
Need help to create a login user form in Microsoft Excel Henriksen MS Office Support 2 23-02-2012 05:04 PM
User Add Data Pop up box in Microsoft Excel Tur^turro MS Office Support 3 11-01-2012 03:51 PM
cannot open excel after change user name bunnie Windows Software 1 27-12-2009 05:40 PM
Create user defined functions in Excel 2007 AbhayD Windows Software 3 24-06-2009 07:05 PM


All times are GMT +5.5. The time now is 07:19 AM.