VBA/Excel/Access/Word/Application/Application OnKey
Содержание
Change the Down Arrow Key
<source lang="vb">
Sub AssignDown()
Application.OnKey "{Down}", "DownTen"
End Sub
</source>
Deactivate ^c
<source lang="vb">
Sub StopCopyShortCut()
Application.OnKey "^c", ""
End Sub
</source>
Reactivate ^c
<source lang="vb">
Sub ClearCopyShortCut()
Application.OnKey "^c"
End Sub
</source>
Restore Down Arrow key
<source lang="vb">
Sub ClearDown()
Application.OnKey "{Down}"
End Sub
</source>
Use Application.OnKey to register sub module with key stroke
<source lang="vb">
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
</source>
use the OnKey method to assign a macro procedure to a single keystroke or any combination of Ctrl, Shift, and Alt with another key.
<source lang="vb"> Sub AssignDown() Application.OnKey "{Down}", "DownTen" End Sub Sub DownTen() ActiveCell.Offset(10, 0).Select End Sub Sub ClearDown() Application.OnKey "{Down}" End Sub </source>