Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Have a bit of code with this simplified construction:
Sub Test() On Error GoTo STOPTEST Application.EnableCancelKey = xlErrorHandler OtherSub Do While Condition = True DoEvents OtherSub DoEvents Loop STOPTEST: MsgBox "Stopped Test" End Sub Now when I am in the Sub OtherSub the Escape key will interrupt this code and go to STOPTEST, but not when I am in the Do While loop and not in OtherSub. Ctrl + Break/Pause will work in both situations. What could be the explanation for this? Ideally I would like the Escape key to work in both situations. RBS |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Bart,
I think it's related to the DoEvents. Also note that if you have an errorhandler in Othersub THAT will take over. e.g. Sub Test() On Error GoTo errProc: Application.EnableCancelKey = xlErrorHandler BusyBee MsgBox "Returned/completed" Exit Sub errProc: MsgBox "Stopped Test" End Sub Sub BusyBee() Dim i#, n#, m# m = 100000000# On Error GoTo errProc: 'note when called from test the key is in effect For i = 1 To m: n = n + 1: Next MsgBox "switch handler" On Error GoTo 0 'each error will now be handled by the handler from the caller. 'but the enablekey is still active.. For i = 1 To m: n = n + 1: Next MsgBox "from now on Esc wont work" For i = 1 To m n = n + 1: If n Mod 1000 Then DoEvents Next Exit Sub errProc: If MsgBox("Stopped Other... Continue?", vbYesNo) = vbYes Then Resume Else End End If End Sub hth -- keepITcool | www.XLsupport.com | keepITcool chello nl | amsterdam RB Smissaert wrote : Have a bit of code with this simplified construction: Sub Test() On Error GoTo STOPTEST Application.EnableCancelKey = xlErrorHandler OtherSub Do While Condition = True DoEvents OtherSub DoEvents Loop STOPTEST: MsgBox "Stopped Test" End Sub Now when I am in the Sub OtherSub the Escape key will interrupt this code and go to STOPTEST, but not when I am in the Do While loop and not in OtherSub. Ctrl + Break/Pause will work in both situations. What could be the explanation for this? Ideally I would like the Escape key to work in both situations. RBS |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi keepITcool,
I still don't quite get it. The Sub OtherSub has no error handler. Leaving out one or both of the DoEvents statements makes matters worse as Excel will just freeze or crash on pressing the Escape key, so I need these. I have done a bit more reading about this and it seems that Ctrl + Pause/Break is just more reliable than Escape. I am in Excel 2002. Maybe I need some API to capture a keypress and take action according. RBS "keepITcool" wrote in message ft.com... Hi Bart, I think it's related to the DoEvents. Also note that if you have an errorhandler in Othersub THAT will take over. e.g. Sub Test() On Error GoTo errProc: Application.EnableCancelKey = xlErrorHandler BusyBee MsgBox "Returned/completed" Exit Sub errProc: MsgBox "Stopped Test" End Sub Sub BusyBee() Dim i#, n#, m# m = 100000000# On Error GoTo errProc: 'note when called from test the key is in effect For i = 1 To m: n = n + 1: Next MsgBox "switch handler" On Error GoTo 0 'each error will now be handled by the handler from the caller. 'but the enablekey is still active.. For i = 1 To m: n = n + 1: Next MsgBox "from now on Esc wont work" For i = 1 To m n = n + 1: If n Mod 1000 Then DoEvents Next Exit Sub errProc: If MsgBox("Stopped Other... Continue?", vbYesNo) = vbYes Then Resume Else End End If End Sub hth -- keepITcool | www.XLsupport.com | keepITcool chello nl | amsterdam RB Smissaert wrote : Have a bit of code with this simplified construction: Sub Test() On Error GoTo STOPTEST Application.EnableCancelKey = xlErrorHandler OtherSub Do While Condition = True DoEvents OtherSub DoEvents Loop STOPTEST: MsgBox "Stopped Test" End Sub Now when I am in the Sub OtherSub the Escape key will interrupt this code and go to STOPTEST, but not when I am in the Do While loop and not in OtherSub. Ctrl + Break/Pause will work in both situations. What could be the explanation for this? Ideally I would like the Escape key to work in both situations. RBS |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"RB Smissaert" wrote in message
... I have done a bit more reading about this and it seems that Ctrl + Pause/Break is just more reliable than Escape. You have hit the nail on the head, RBS. This has been my personal experience. I am in Excel 2002. Maybe I need some API to capture a keypress and take action according. Perhaps you are looking for something like this: http://groups-beta.google.com/group/...97f656cd?hl=en Regards, Vasant |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Vasant,
Thanks, that looks like a nice and simple API and will give that a try. RBS "Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message ... "RB Smissaert" wrote in message ... I have done a bit more reading about this and it seems that Ctrl + Pause/Break is just more reliable than Escape. You have hit the nail on the head, RBS. This has been my personal experience. I am in Excel 2002. Maybe I need some API to capture a keypress and take action according. Perhaps you are looking for something like this: http://groups-beta.google.com/group/...97f656cd?hl=en Regards, Vasant |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Vasant,
Tried that API and it works perfect. Thanks again for the tip. RBS "Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message ... "RB Smissaert" wrote in message ... I have done a bit more reading about this and it seems that Ctrl + Pause/Break is just more reliable than Escape. You have hit the nail on the head, RBS. This has been my personal experience. I am in Excel 2002. Maybe I need some API to capture a keypress and take action according. Perhaps you are looking for something like this: http://groups-beta.google.com/group/...97f656cd?hl=en Regards, Vasant |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Glad to help, RBS!
-- Vasant "RB Smissaert" wrote in message ... Vasant, Tried that API and it works perfect. Thanks again for the tip. RBS "Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message ... "RB Smissaert" wrote in message ... I have done a bit more reading about this and it seems that Ctrl + Pause/Break is just more reliable than Escape. You have hit the nail on the head, RBS. This has been my personal experience. I am in Excel 2002. Maybe I need some API to capture a keypress and take action according. Perhaps you are looking for something like this: http://groups-beta.google.com/group/...97f656cd?hl=en Regards, Vasant |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Is there a difference between CTRL+D and CTRL+" (quotation marks) | Excel Discussion (Misc queries) | |||
Ctrl+Alt+Break | Excel Programming | |||
Can Not Get Macro to Break with CTRL-BREAK | Excel Programming | |||
Control Break and Escape for Interrupting Code | Excel Programming | |||
Message box that does not interrupt code | Excel Programming |