Use Application.OnKey to register sub module with key stroke : Application OnKey « Application « VBA / Excel / Access / Word






Use Application.OnKey to register sub module with key stroke

 
Sub Setup_OnKey()
    Application.OnKey "{PgDn}", "PgDn_Sub"
    Application.OnKey "{PgUp}", "PgUp_Sub"
    MsgBox "PgUp and PgDown have been re-mapped."
End Sub

Sub Cancel_OnKey()
    Application.OnKey "{PgDn}"
    Application.OnKey "{PgUp}"
    MsgBox "PgUp and PgDown have been restored to normal."
End Sub

Sub PgDn_Sub()
    On Error Resume Next
    ActiveCell.Offset(1, 0).Activate
End Sub

Sub PgUp_Sub()
    On Error Resume Next
    ActiveCell.Offset(-1, 0).Activate
End Sub

 








Related examples in the same category

1.Change the Down Arrow Key
2.Restore Down Arrow key
3.use the OnKey method to assign a macro procedure to a single keystroke or any combination of Ctrl, Shift, and Alt with another key.
4.Deactivate ^c
5.Reactivate ^c