PDA

View Full Version : Calling Function Keys



Rasm
02-17-2012, 06:23 AM
I have been trying to trap the F1 function key - I have tried two methods - see code below - But I cannot trap the F1 key or the TAB key(using TAB here just so they are different calls) - My code is called from a UserForm (when it is activated) - wondering if that is why it is not working



Private Sub DemoOnKey()
Application.OnKey "{TAB}", "Message"
End Sub

Private Sub Message()
Call ReadHelpFile(Language)
End Sub

Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case vbKeyF1
Call ReadHelpFile(Language)
End Select
End Sub

PcMax
02-18-2012, 01:38 AM
Hi,

Test in this way:


Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyF1 Then
'your code here
MsgBox "Hallo!"
End If
End Sub