VBA/Excel/Access/Word/Application/Application OnKey

Материал из VB Эксперт
Перейти к: навигация, поиск

Change the Down Arrow Key

 
Sub AssignDown()
   Application.OnKey "{Down}", "DownTen"
End Sub



Deactivate ^c

 
Sub StopCopyShortCut()
   Application.OnKey "^c", ""
End Sub



Reactivate ^c

 
Sub ClearCopyShortCut()
  Application.OnKey "^c"
End Sub



Restore Down Arrow key

 
Sub ClearDown()
   Application.OnKey "{Down}"
End Sub



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



use the OnKey method to assign a macro procedure to a single keystroke or any combination of Ctrl, Shift, and Alt with another key.

 
     Sub AssignDown()
         Application.OnKey "{Down}", "DownTen"
     End Sub
     Sub DownTen()
         ActiveCell.Offset(10, 0).Select
     End Sub
     Sub ClearDown()
         Application.OnKey "{Down}"
     End Sub