ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hotkeys (https://www.excelbanter.com/excel-programming/430748-hotkeys.html)

Greg B[_17_]

Hotkeys
 
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



Patrick Molloy

Hotkeys
 
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




"Greg B" wrote in message
...
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



Greg B[_17_]

Hotkeys
 

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

Thanks again

Greg B

"Patrick Molloy" wrote in message
...
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




"Greg B" wrote in message
...
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



Patrick Molloy

Hotkeys
 

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

"Greg B" wrote in message
...
Thanks for that,
Where can I get a list of the numbers for keys? Would be a great help.

Thanks again

Greg B

"Patrick Molloy" wrote in message
...
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




"Greg B" wrote in message
...
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



Greg B[_17_]

Hotkeys
 
Wow that is pretty handy, Thanks Again
Greg B

"Patrick Molloy" wrote in message
...
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

"Greg B" wrote in message
...
Thanks for that,
Where can I get a list of the numbers for keys? Would be a great help.

Thanks again

Greg B

"Patrick Molloy" wrote in message
...
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




"Greg B" wrote in message
...
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



Peter T

Hotkeys
 

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


"Greg B" wrote in message
...
Thanks for that,
Where can I get a list of the numbers for keys? Would be a great help.

Thanks again

Greg B

"Patrick Molloy" wrote in message
...
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




"Greg B" wrote in message
...
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





Rick Rothstein

Hotkeys
 
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).

--
Rick (MVP - Excel)


"Greg B" wrote in message
...
Thanks for that,
Where can I get a list of the numbers for keys? Would be a great help.

Thanks again

Greg B

"Patrick Molloy" wrote in message
...
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




"Greg B" wrote in message
...
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




Greg B[_17_]

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

Greg B

"Rick Rothstein" wrote in message
...
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).

--
Rick (MVP - Excel)


"Greg B" wrote in message
...
Thanks for that,
Where can I get a list of the numbers for keys? Would be a great help.

Thanks again

Greg B

"Patrick Molloy" wrote in message
...
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




"Greg B" wrote in message
...
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





All times are GMT +1. The time now is 03:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com