Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Is there a way to utilize the event of a user pressing the Enter Key
ONLY. I understand the keypress event itself, but I want to isolate it or at least be able to capture and determine which key was pressed. I want to run a routine only when the user presses the "Enter Key" and have it not fire when any other key is pressed. Does anyone know a good way to go about this? Thanks in advance for any help you can lend. Coby. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Use this structure inside the KeyPress event...
If KeyAscii = 13 Then ' The EnterKey was pressed, run your code here KeyAscii = 0 End If The KeyAscii = 0 statement has the effect of canceling the KeyPress (especially needed to stop the beep sound in a single-line TextBox). Rick "Coby" wrote in message ... Is there a way to utilize the event of a user pressing the Enter Key ONLY. I understand the keypress event itself, but I want to isolate it or at least be able to capture and determine which key was pressed. I want to run a routine only when the user presses the "Enter Key" and have it not fire when any other key is pressed. Does anyone know a good way to go about this? Thanks in advance for any help you can lend. Coby. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Feb 6, 7:44 pm, "Rick Rothstein \(MVP - VB\)"
wrote: Use this structure inside the KeyPress event... If KeyAscii = 13 Then ' The EnterKey was pressed, run your code here KeyAscii = 0 End If The KeyAscii = 0 statement has the effect of canceling the KeyPress (especially needed to stop the beep sound in a single-line TextBox). Rick "Coby" wrote in message ... Is there a way to utilize the event of a user pressing the Enter Key ONLY. I understand the keypress event itself, but I want to isolate it or at least be able to capture and determine which key was pressed. I want to run a routine only when the user presses the "Enter Key" and have it not fire when any other key is pressed. Does anyone know a good way to go about this? Thanks in advance for any help you can lend. Coby. I think that will work perfect. I have been playing with it, but have run into one problem and maybe you have seen this. It seems that since the KeyAscii = 0 line of code executed no key press events work for the form anymore even after restarting the application. Do you know how to get the key press event to work again? Whether it was that command or not there must be a way to get the form object to turn its keypress events back to enabled? I like the full control of your approach which will work very fast, too. Thanks for the help. Coby. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Feb 6, 7:44 pm, "Rick Rothstein \(MVP - VB\)"
wrote: Use this structure inside the KeyPress event... If KeyAscii = 13 Then ' The EnterKey was pressed, run your code here KeyAscii = 0 End If The KeyAscii = 0 statement has the effect of canceling the KeyPress (especially needed to stop the beep sound in a single-line TextBox). Rick "Coby" wrote in message ... Is there a way to utilize the event of a user pressing the Enter Key ONLY. I understand the keypress event itself, but I want to isolate it or at least be able to capture and determine which key was pressed. I want to run a routine only when the user presses the "Enter Key" and have it not fire when any other key is pressed. Does anyone know a good way to go about this? Thanks in advance for any help you can lend. Coby. I think that will work perfect. I have been playing with it, but have run into one problem and maybe you have seen this. It seems that since the KeyAscii = 0 line of code executed no key press events work for the form anymore even after restarting the application. Do you know how to get the key press event to work again? Whether it was that command or not there must be a way to get the form object to turn its keypress events back to enabled? I like the full control of your approach which will work very fast, too. KeyAscii = 0 can only affect the one time it is executed... what it does is substitute the value of 0 for the value passed into the KeyPress press event (see the KeyAscii argument in the event declaration statement) by the system for that one event execution only... it cannot be responsible for the problem you are describing. Do you by any chance have an Application.EnableEvents=False statement in your code (which was to be followed by an Application.EnableEvents=True statement later on)? If so, it sounds like your program exited before you got a chance to set it back to True (something that should be taken care of by an On Error statement or logic before an Exit Sub/Function). If this is the case, just execute Application.EnableEvents=True in the Immediate window to straighten things back out. If not, you will need to show us your code so we can see what is going on. Rick |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Feb 7, 7:03*am, "Rick Rothstein \(MVP - VB\)"
wrote: On Feb 6, 7:44 pm, "Rick Rothstein \(MVP - VB\)" wrote: Use this structure inside the KeyPress event... If KeyAscii = 13 Then * ' *The EnterKey was pressed, run your code here * KeyAscii = 0 End If The KeyAscii = 0 statement has the effect of canceling the KeyPress (especially needed to stop the beep sound in a single-line TextBox). Rick "Coby" wrote in message ... Is there a way to utilize the event of a user pressing the Enter Key ONLY. I understand the keypress event itself, but I want to isolate it or at least be able to capture and determine which key was pressed. I want to run a routine only when the user presses the "Enter Key" and have it not fire when any other key is pressed. Does anyone know a good way to go about this? Thanks in advance for any help you can lend. Coby. I think that will work perfect. *I have been playing with it, but have run into one problem and maybe you have seen this. It seems that since the KeyAscii = 0 line of code executed no key press events work for the form anymore even after restarting the application. Do you know how to get the key press event to work again? Whether it was that command or not there must be a way to get the form object to turn its keypress events back to enabled? I like the full control of your approach which will work very fast, too. KeyAscii = 0 can only affect the one time it is executed... what it does is substitute the value of 0 for the value passed into the KeyPress press event (see the KeyAscii argument in the event declaration statement) by the system for that one event execution only... it cannot be responsible for the problem you are describing. Do you by any chance have an Application.EnableEvents=False statement in your code (which was to be followed by an Application.EnableEvents=True statement later on)? If so, it sounds like your program exited before you got a chance to set it back to True (something that should be taken care of by an On Error statement or logic before an Exit Sub/Function). If this is the case, just execute Application.EnableEvents=True in the Immediate window to straighten things back out. If not, you will need to show us your code so we can see what is going on. Rick- Hide quoted text - - Show quoted text - The problem is all me (pebkac). . . Other events were still working, but I set application events to true and still could not get it to fire. But, (1) I was trying to execute it on the entrire form, not the text box object then (2) I was using a keypress instead of keydown, etc. I have it all worked out now and this will allow me to move on to some new things I am wanting to do. Your help is greatly appreciated Thanks, Coby. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro to select cells in column enter data then press enter | New Users to Excel | |||
Enter data and press enter to move to specific cell | Excel Programming | |||
Key Press Event | Excel Programming | |||
When I Press the Enter Key Nothing happens. | Excel Discussion (Misc queries) | |||
key press event? | Excel Programming |