PC Review


Reply
Thread Tools Rate Thread

How to cancel midway?

 
 
Sing
Guest
Posts: n/a
 
      5th Nov 2007
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 With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      5th Nov 2007
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" <(E-Mail Removed)> wrote in message
news:fgn1jt$jrk$(E-Mail Removed)...
> 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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PC keeps shutting down midway through game =?Utf-8?B?VDk1NTI=?= Windows XP Games 4 31st Jul 2006 02:25 PM
XP crashes midway through song The Babaloughesian Windows XP Music 2 4th Mar 2005 01:43 AM
SP2 downloads stop midway Carlos A. Windows XP Performance 1 26th Sep 2004 06:31 PM
dvd freezes midway during playback Eric Windows XP Video 1 22nd Dec 2003 04:11 PM
Pc reboots midway thru power up Paul Microsoft Windows 2000 File System 1 29th Nov 2003 05:48 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:43 AM.