Wednesday, May 7, 2014

Application.OnKey Example

Application.Onkey method runs a specified procedure when a particular key or key combination is pressed.


Sub test()
Call onKeyExample(True, True, True, "z", "myprocedure")

End Sub

Sub onKeyExample(shiftkey As Boolean, ctrlkey As Boolean, altkey As Boolean, strkey As String, callfunction As String)
Dim strShift As String
Dim strCtrl As String
Dim stralt As String
    If (shiftkey = True) Then strShift = "+"
    If (ctrlkey = True) Then strCtrl = "^"
    If (altkey = True) Then stralt = "%"
 
 
    Application.OnKey strShift & strCtrl & stralt & "{" & strkey & "}", callfunction
End Sub

Sub myprocedure()
    MsgBox "My Procedure"

End Sub