Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Option Button Accelerator Key

I have a UserForm with several option buttons, each with its own
accelerator.
Is there a way to set the accelerator to work without the ALT key? I'd like
the users to be able to hit just one key to choose the particular option.

TIA


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Option Button Accelerator Key

"Bob Wall" wrote in message
...
I have a UserForm with several option buttons, each with its own
accelerator.
Is there a way to set the accelerator to work without the ALT key? I'd

like
the users to be able to hit just one key to choose the particular option.


Hi Bob,

There's no way to do this directly, but if you don't have any controls
on the UserForm that require data entry, meaning you can safely hijack
keystrokes, you can roll your own. Create a UserForm with three
OptionButtons. Leave them with their default names and captions so you have
OptionButton1, OptionButton2 and OptionButton3. To allow the user to select
them by just pressing 1, 2 or 3, respectively, you would add the following
code to the UserForm:

Private Sub OptionButton1_KeyPress( _
ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 49 Then ''' 1
OptionButton1.SetFocus
OptionButton1.Value = True
KeyAscii = 0
ElseIf KeyAscii = 50 Then ''' 2
OptionButton2.SetFocus
OptionButton2.Value = True
KeyAscii = 0
ElseIf KeyAscii = 51 Then ''' 3
OptionButton3.SetFocus
OptionButton3.Value = True
KeyAscii = 0
End If
End Sub

Private Sub OptionButton2_KeyPress( _
ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 49 Then ''' 1
OptionButton1.SetFocus
OptionButton1.Value = True
KeyAscii = 0
ElseIf KeyAscii = 50 Then ''' 2
OptionButton2.SetFocus
OptionButton2.Value = True
KeyAscii = 0
ElseIf KeyAscii = 51 Then ''' 3
OptionButton3.SetFocus
OptionButton3.Value = True
KeyAscii = 0
End If
End Sub

Private Sub OptionButton3_KeyPress( _
ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 49 Then ''' 1
OptionButton1.SetFocus
OptionButton1.Value = True
KeyAscii = 0
ElseIf KeyAscii = 50 Then ''' 2
OptionButton2.SetFocus
OptionButton2.Value = True
KeyAscii = 0
ElseIf KeyAscii = 51 Then ''' 3
OptionButton3.SetFocus
OptionButton3.Value = True
KeyAscii = 0
End If
End Sub

If you have additional controls on the UserForm you need to add a similar
KeyPress event for each of them, with additional ElseIf branches for each
accelerator key you want to simulate.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Option Button Accelerator Key

About a year and a half ago I posted a similar question. With help from
this newsgroup, I ended up creating a Keyup event macro for each button.
The Keyup event gets the code of the key that was pressed. For example...

Private Sub Cancel_Button_Keyup(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Call WhichKey(CInt(KeyCode))
End Sub

Each of the Keyup macros looks like this. The WhickKey macro then looks
like this...

Sub WhichKey(KeyCode As Integer)
Select Case KeyCode
Case 65, 97 'A,a
Call AppendOverwriteDialog_Append_Button_Click
Case 79, 111 'O,o
Call AppendOverwriteDialog_Overwrite_Button_Click
Case 67, 113 'C,c
Call Cancel_Button_Click
Case 72, 104 'H,h
Call Help_Button_Click
Case Else
End Select
End Sub



Brian Murphy
Austin, Texas




"Rob Bovey" wrote in message
...
"Bob Wall" wrote in message
...
I have a UserForm with several option buttons, each with its own
accelerator.
Is there a way to set the accelerator to work without the ALT key? I'd

like
the users to be able to hit just one key to choose the particular

option.

Hi Bob,

There's no way to do this directly, but if you don't have any controls
on the UserForm that require data entry, meaning you can safely hijack
keystrokes, you can roll your own. Create a UserForm with three
OptionButtons. Leave them with their default names and captions so you

have
OptionButton1, OptionButton2 and OptionButton3. To allow the user to

select
them by just pressing 1, 2 or 3, respectively, you would add the following
code to the UserForm:

Private Sub OptionButton1_KeyPress( _
ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 49 Then ''' 1
OptionButton1.SetFocus
OptionButton1.Value = True
KeyAscii = 0
ElseIf KeyAscii = 50 Then ''' 2
OptionButton2.SetFocus
OptionButton2.Value = True
KeyAscii = 0
ElseIf KeyAscii = 51 Then ''' 3
OptionButton3.SetFocus
OptionButton3.Value = True
KeyAscii = 0
End If
End Sub

Private Sub OptionButton2_KeyPress( _
ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 49 Then ''' 1
OptionButton1.SetFocus
OptionButton1.Value = True
KeyAscii = 0
ElseIf KeyAscii = 50 Then ''' 2
OptionButton2.SetFocus
OptionButton2.Value = True
KeyAscii = 0
ElseIf KeyAscii = 51 Then ''' 3
OptionButton3.SetFocus
OptionButton3.Value = True
KeyAscii = 0
End If
End Sub

Private Sub OptionButton3_KeyPress( _
ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 49 Then ''' 1
OptionButton1.SetFocus
OptionButton1.Value = True
KeyAscii = 0
ElseIf KeyAscii = 50 Then ''' 2
OptionButton2.SetFocus
OptionButton2.Value = True
KeyAscii = 0
ElseIf KeyAscii = 51 Then ''' 3
OptionButton3.SetFocus
OptionButton3.Value = True
KeyAscii = 0
End If
End Sub

If you have additional controls on the UserForm you need to add a similar
KeyPress event for each of them, with additional ElseIf branches for each
accelerator key you want to simulate.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *





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
keep source formatting is not an option in paste option button Tina Excel Discussion (Misc queries) 0 February 20th 06 09:58 PM
Analysis Services accelerator for Excel deployment Alex Valkov Excel Programming 0 July 12th 04 01:41 AM
Accelerator Keys Nigel[_5_] Excel Programming 1 October 21st 03 10:13 PM
value of option button paradise Excel Programming 1 September 30th 03 04:30 AM
appactivate sendkeys not working with accelerator RB Smissaert Excel Programming 4 August 12th 03 08:31 PM


All times are GMT +1. The time now is 08:25 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"