Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to cancel midway?
Dear Excel Gurus,
I have VBA code that takes about 5 minutes to run. Sometimes, I want to cancel it halfway. Can I add a new "Cancel" button to cancel the operation? What code should I put for that button? Thanks for your advice. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to cancel midway?
The simplest way is to set the Application.EnableCancelKey property to
xlErrorHandler. This will raise a run time error when the user presses CTRL BREAK. For example, Sub AAA() Application.EnableCancelKey = xlErrorHandler On Error GoTo ErrH: ' ' your code here ' Exit Sub ErrH: If Err.Number = 18 Then MsgBox "You pressed CTRL+BREAK" Else ' other error handling End If End Sub -- Cordially, Chip Pearson Microsoft MVP - Excel, 10 Years Pearson Software Consulting www.cpearson.com (email on the web site) "Sing" wrote in message ... Dear Excel Gurus, I have VBA code that takes about 5 minutes to run. Sometimes, I want to cancel it halfway. Can I add a new "Cancel" button to cancel the operation? What code should I put for that button? Thanks for your advice. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Workbook_BeforeClose(Cancel As Boolean) - Cancel won't work | Setting up and Configuration of Excel | |||
Input box to cancel sub when Cancel is clicked. | Excel Programming | |||
Disabling 'Cancel' option when saving work (Yes/No/Cancel) | Excel Programming | |||
Cancel button to cancel the whole macro | Excel Programming | |||
Cancel Macro is user selects 'cancel' at save menu | Excel Programming |