OnKey {ESC} not working? 
Author Message
 OnKey {ESC} not working?

Hi all
I would like to call sub when the user presses the escape key so i went:
Sub Macro()
Application.OnKey "{ESC}","MyProc"
'Do things etc...
'Do other things etc...
End Sub
Sub MyProc()
Msgbox "You've just stopped this macro running!"
End Sub
But this is inoperant as Macro keeps running?
Any ideas on how to achieve this?
TIA
Cheers
Pascal
France


Tue, 02 Dec 2003 22:08:30 GMT  
 OnKey {ESC} not working?
Hi Pascal,

I am not sure Application.OnKey would work while a macro is running.
You might want to use Application.EnableCancelKey. And set its value
to go to Error Handler when error is occured. Also make sure the
error is occured because of "ESC" only. Please look in the following
routine and I hope this helps. You might want to reset the values
to default.

-Srini.

Sub Macro()

On Error GoTo ErrorHandler:

Application.EnableCancelKey = xlErrorHandler
'Do things etc...
'Do other things etc...

On Error GoTo 0

Application.EnableCancelKey = xlInterrupt

Exit Sub

ErrorHandler:

    if Err.Number = 18 then MyProc

End Sub

Quote:
-----Original Message-----

Hi all
I would like to call sub when the user presses the escape key so i went:
Sub Macro()
Application.OnKey "{ESC}","MyProc"
'Do things etc...
'Do other things etc...
End Sub
Sub MyProc()
Msgbox "You've just stopped this macro running!"
End Sub
But this is inoperant as Macro keeps running?
Any ideas on how to achieve this?
TIA
Cheers
Pascal
France

.



Tue, 02 Dec 2003 23:55:06 GMT  
 OnKey {ESC} not working?
Hi srini
Thanks for your help.
This does not work: I still keep getting the usal VB message for
interruption so my myproc is not running
Thanks anyway
Cordially
Pascal
France



Quote:
> Hi Pascal,

> I am not sure Application.OnKey would work while a macro is running.
> You might want to use Application.EnableCancelKey. And set its value
> to go to Error Handler when error is occured. Also make sure the
> error is occured because of "ESC" only. Please look in the following
> routine and I hope this helps. You might want to reset the values
> to default.

> -Srini.

> Sub Macro()

> On Error GoTo ErrorHandler:

> Application.EnableCancelKey = xlErrorHandler
> 'Do things etc...
> 'Do other things etc...

> On Error GoTo 0

> Application.EnableCancelKey = xlInterrupt

> Exit Sub

> ErrorHandler:

>     if Err.Number = 18 then MyProc

> End Sub

> -----Original Message-----
> Hi all
> I would like to call sub when the user presses the escape key so i went:
> Sub Macro()
> Application.OnKey "{ESC}","MyProc"
> 'Do things etc...
> 'Do other things etc...
> End Sub
> Sub MyProc()
> Msgbox "You've just stopped this macro running!"
> End Sub
> But this is inoperant as Macro keeps running?
> Any ideas on how to achieve this?
> TIA
> Cheers
> Pascal
> France

> .



Wed, 03 Dec 2003 00:07:58 GMT  
 OnKey {ESC} not working?
Hi Pascal,

It works on mine. Check in VBE , whether Tools--> Options
In General Tab, under Error Trapping set to
"Break on Unhandled Errors".

-Srini.

Quote:
-----Original Message-----

Hi srini
Thanks for your help.
This does not work: I still keep getting the usal VB message for
interruption so my myproc is not running
Thanks anyway
Cordially
Pascal
France



> Hi Pascal,

> I am not sure Application.OnKey would work while a macro is running.
> You might want to use Application.EnableCancelKey. And set its value
> to go to Error Handler when error is occured. Also make sure the
> error is occured because of "ESC" only. Please look in the following
> routine and I hope this helps. You might want to reset the values
> to default.

> -Srini.

> Sub Macro()

> On Error GoTo ErrorHandler:

> Application.EnableCancelKey = xlErrorHandler
> 'Do things etc...
> 'Do other things etc...

> On Error GoTo 0

> Application.EnableCancelKey = xlInterrupt

> Exit Sub

> ErrorHandler:

>     if Err.Number = 18 then MyProc

> End Sub

> -----Original Message-----
> Hi all
> I would like to call sub when the user presses the escape key so i went:
> Sub Macro()
> Application.OnKey "{ESC}","MyProc"
> 'Do things etc...
> 'Do other things etc...
> End Sub
> Sub MyProc()
> Msgbox "You've just stopped this macro running!"
> End Sub
> But this is inoperant as Macro keeps running?
> Any ideas on how to achieve this?
> TIA
> Cheers
> Pascal
> France

> .

.



Wed, 03 Dec 2003 08:31:51 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. OnKey method not working

2. OnKey Example Not Working

3. OnKey fuction does not work with number keys

4. OnKey problem: disabling ^V doesn't work

5. OnKey macro won't work

6. onkey - not quite as I expected

7. All keys are not equal for OnKey?

8. ESC key clears an entire form, i do not want this

9. Form will not advance without ESC key

10. Autorun not working, Photoedit resize icon not working


 
Powered by phpBB® Forum Software © phpBB Group