Results 1 to 2 of 2

Thread: Calling Function Keys

  1. #1
    Senior Member
    Join Date
    Apr 2011
    Posts
    190
    Rep Power
    14

    Calling Function Keys

    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

    Code:
    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
    xl2007 - Windows 7
    xl hates the 255 number

  2. #2
    Senior Member
    Join Date
    Oct 2011
    Posts
    135
    Rep Power
    14
    Hi,

    Test in this way:

    Code:
    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

Similar Threads

  1. UDF (user defined function) replacement for Excel's DATEDIF function
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 21
    Last Post: 03-07-2015, 09:47 PM
  2. Calling UDFs by Hyperlink
    By Rajan_Verma in forum Rajan Verma's Corner
    Replies: 0
    Last Post: 06-06-2013, 07:53 PM
  3. Calling another macro in same workbook
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 4
    Last Post: 08-18-2012, 12:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •