Listening keyboard events on UserForm (eg :UserForm_KeyPress)
Listening keyboard events on UserForm (eg :UserForm_KeyPress)
(OP)
Hi ;
All is in the title.
On a macro with one UserForm, I want to catch some keyboard events.
EG : Escape key to end the macro.
I tried to use "Private Sub UserForm_KeyPress( ByVal KeyANSI As MSForms.ReturnInteger)" but unfortunatly, it doesn't work.
I copy/paste my sub on an excel macro, and it perfectly works.
I would like to avoid to listen keyboard events on each controls ...
Thanks for your tips.
All is in the title.
On a macro with one UserForm, I want to catch some keyboard events.
EG : Escape key to end the macro.
I tried to use "Private Sub UserForm_KeyPress( ByVal KeyANSI As MSForms.ReturnInteger)" but unfortunatly, it doesn't work.
I copy/paste my sub on an excel macro, and it perfectly works.
I would like to avoid to listen keyboard events on each controls ...
Thanks for your tips.
SW2007 SP5
Worksatation HP wx4300 2GB
NVidia Quadro FX 3450






RE: Listening keyboard events on UserForm (eg :UserForm_KeyPress)
The best way to do this is to make a function that would react to keys, then have each control keypress event simply call that function. This is less tedious than writing full code for each control. If you need to interrupt a loop, be sure the loop has DoEvents call within its body.
Sometimes, when testing a form, I put a temporary "Break" command button on the form. Easier than monitoring for KeyPress events.
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: Listening keyboard events on UserForm (eg :UserForm_KeyPress)
That's what I've ever done, but I think it isn't clean ...
Whereas it works on Excel, I don't understand why it doesn't on SW ... !!!
Ho ! Thanks for your tip about DoEvents that I didn't know ; sure it's useful ...
SW2007 SP5
Worksatation HP wx4300 2GB
NVidia Quadro FX 3450