Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Activating a command button with a single key stroke

Is there a way to activate a command button by simply pressing a single
letter on the keyboard? For example, say I have a button that says "Add A
Title". When I press the A key I want the button to activate and process
whatever code is attached to it.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Activating a command button with a single key stroke

Use the keydown event of the command button. or the userform..

Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
If KeyCode = 65 Then MsgBox "Run"
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

Is there a way to activate a command button by simply pressing a single
letter on the keyboard? For example, say I have a button that says "Add A
Title". When I press the A key I want the button to activate and process
whatever code is attached to it.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Activating a command button with a single key stroke

You could use the Accelerator property, but then use alt-A to run the _click
event for that command button. (Include the A somewhere in the caption!)

Kind of like what you see in the xl2003 menu--where the F in File is underlined,
E in Edit, etc.

Bishop wrote:

Is there a way to activate a command button by simply pressing a single
letter on the keyboard? For example, say I have a button that says "Add A
Title". When I press the A key I want the button to activate and process
whatever code is attached to it.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Activating a command button with a single key stroke

You could use the Accelerator property, but then use alt-A to run the _click
event for that command button. (Include the A somewhere in the caption!)

Kind of like what you see in the xl2003 menu--where the F in File is underlined,
E in Edit, etc.

Bishop wrote:

Is there a way to activate a command button by simply pressing a single
letter on the keyboard? For example, say I have a button that says "Add A
Title". When I press the A key I want the button to activate and process
whatever code is attached to it.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Activating a command button with a single key stroke

read help on
APPLICATION.ONKEY key, procedure

when this is run
APPLICATION.ONKEY "Q", "doThis"

whenever the user presses the Q key, the sub called doThis is run


"Bishop" wrote in message
...
Is there a way to activate a command button by simply pressing a single
letter on the keyboard? For example, say I have a button that says "Add A
Title". When I press the A key I want the button to activate and process
whatever code is attached to it.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Activating a command button with a single key stroke

read help on
APPLICATION.ONKEY key, procedure

when this is run
APPLICATION.ONKEY "Q", "doThis"

whenever the user presses the Q key, the sub called doThis is run


"Bishop" wrote in message
...
Is there a way to activate a command button by simply pressing a single
letter on the keyboard? For example, say I have a button that says "Add A
Title". When I press the A key I want the button to activate and process
whatever code is attached to it.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Activating a command button with a single key stroke

I have the following code:

Private Sub AddButton_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)

Dim A As Integer

If KeyCode = A Then
AddTitle.Show
End If

End Sub

but it doesn't work. What am I doing wrong?

"Jacob Skaria" wrote:

Use the keydown event of the command button. or the userform..

Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
If KeyCode = 65 Then MsgBox "Run"
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

Is there a way to activate a command button by simply pressing a single
letter on the keyboard? For example, say I have a button that says "Add A
Title". When I press the A key I want the button to activate and process
whatever code is attached to it.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Activating a command button with a single key stroke

Its returning the character code..65 for A and so on..However if you are
unfamilar use the below code....

Dim A As Integer

If Chr(KeyCode) = "A" Then
AddTitle.Show
End If

If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

I have the following code:

Private Sub AddButton_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)

Dim A As Integer

If KeyCode = A Then
AddTitle.Show
End If

End Sub

but it doesn't work. What am I doing wrong?

"Jacob Skaria" wrote:

Use the keydown event of the command button. or the userform..

Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
If KeyCode = 65 Then MsgBox "Run"
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

Is there a way to activate a command button by simply pressing a single
letter on the keyboard? For example, say I have a button that says "Add A
Title". When I press the A key I want the button to activate and process
whatever code is attached to it.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Activating a command button with a single key stroke

Its returning the character code..65 for A and so on..However if you are
unfamilar use the below code....

Dim A As Integer

If Chr(KeyCode) = "A" Then
AddTitle.Show
End If

If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

I have the following code:

Private Sub AddButton_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)

Dim A As Integer

If KeyCode = A Then
AddTitle.Show
End If

End Sub

but it doesn't work. What am I doing wrong?

"Jacob Skaria" wrote:

Use the keydown event of the command button. or the userform..

Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
If KeyCode = 65 Then MsgBox "Run"
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

Is there a way to activate a command button by simply pressing a single
letter on the keyboard? For example, say I have a button that says "Add A
Title". When I press the A key I want the button to activate and process
whatever code is attached to it.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
activating a command button chuck Excel Discussion (Misc queries) 1 September 10th 09 03:12 AM
Deselect Command Button by Selecting another Command Button gmcnaugh[_2_] Excel Programming 3 September 2nd 08 05:59 PM
VB's Command Button vs Form's Command Button Ronald Dodge Excel Programming 3 May 24th 06 02:23 PM
Button Shortcut / Key Stroke Dan Excel Programming 4 May 27th 05 07:22 PM
Single command button to select one of several choices. Mike Krumel Excel Programming 6 July 18th 03 01:43 PM


All times are GMT +1. The time now is 09:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"