Assign keyboard shortcut to run procedure

前端 未结 9 2094
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 04:35

When I press F5 in the VBA editor I would always like to run my \"Sub Skynet()\" procedure. Is there any way to assign a keyboard shortcut to this procedure.

9条回答
  •  难免孤独
    2020-11-29 05:04

    For assigning a keyboard key to button on the sheet you can use this code, just copy this code to the sheet which contain the button.

    Here Return specifies the key and get_detail is the procedure name.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        Application.OnKey "{RETURN}", "get_detail"
    
    End Sub
    

    Now within this sheet whenever you press Enter button the assigned macro will be called.

提交回复
热议问题