Hotkeys

G

Greg B

Hello and Good morning or evening,

I am wondering about something I have tried a piece of code I found on the
web regarding hotkeys. It will work perfectly in the main excel sheet but I
am hoping to have the capabilities when it has a userform showing. This
code has been put in the open code of the worksheet where would I put it to
be used in the userform?
If this cant happen I am hoping to be able to press 1 button on the keyboard
to shutdown the userform("Sales") and then execute the code for the next
sale.

Application.OnKey "{F3}", "endsale"

Thanks In Advance

Greg B
 
P

Patrick Molloy

you could use the userform's keydown event ...

Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 114 Then ' 114 is F3
endsale
End If
End Sub
 
G

Greg B

Thanks for that,
Where can I get a list of the numbers for keys? Would be a great help.

Thanks again

Greg B
 
P

Patrick Molloy

I'm not sure to be honest - its ages since i last looked at this

to get 114 all I did was drop a label onto a userform

Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Label1.Caption = KeyCode
End Sub
 
G

Greg B

Wow that is pretty handy, Thanks Again
Greg B

Patrick Molloy said:
I'm not sure to be honest - its ages since i last looked at this

to get 114 all I did was drop a label onto a userform

Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Label1.Caption = KeyCode
End Sub
 
P

Peter T

Search KeyCodeConstants in Object browser (F2), select the one that
interests you and look at the bottom. They are also in help but with hex
values.

Regards,
Peter T
 
R

Rick Rothstein

Type keycodes in the VBA search box (upper right corner of window) and
select the first item, it is labeled "Keycode Constants (Visual Basic for
Applications)". You can look for the key you want in the description column
on the right and use the predefined constant listed on the left (this is
more self-documenting than using the numerical value). So, once you find "F3
key" in the description, you can use predefined constant for that keycode,
vbKeyF3, as shown in the left hand listing. So, instead of using...

If KeyCode = 114 Then ' 114 is F3

you can use

If KeyCode = vbKeyF3 Then

instead. Note that the numerical values in the center column are given in
mixed formats (Decimal or Hex) in the center column. The Hex numbers all
start with 0x and if you wanted to use them (again, I am **strongly**
recommending you use the predefined constants instead), you would have to
change the 0x to &h which is VB's way of defining a Hex value. For example,
the 0x72 shown for the F3 key would be &h72 inside your VB code (&h72 is the
same as the decimal value of 114; vbKeyF3 also has a value of 114 which is
why I recommend you use it in the first place).
 
G

Greg B

Thanks Everyone for the help and yes Rick I will follow that advice the
object browser explained it well.

Greg B
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top