View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Patrick Molloy Patrick Molloy is offline
external usenet poster
 
Posts: 1,049
Default cancel message while sub running

I thought application.ONKEY would work, but my test failed.

alternatively, with my test code, run it and the put 1 into cell A1

Option Explicit
Sub cancelled()
Dim i As Long
Dim bCancel As Boolean
bCancel = False
Do
Application.StatusBar = i
i = i + 1
If Range("A1") = 1 Then bCancel = True
DoEvents ' releases control back to PC - ie user can enter data into
the spreadsheet
Loop Until bCancel Or i = 1000000
if bCancel then msgbox "User interrupted!"
End Sub


"tracktraining" wrote in message
...
Hi All,

I would like to create a cancel message that appears while a sub is
running.
So, when the user hit the cancel button on the message box (or userform),
then the sub will exit and start the program from the beginning. And if
the
user doens't hit the cancel button, then the sub will continue to work as
is.

Any help is much appreciated.

thanks,
tracktraining
--
Learning