由于某些原因,我的normal.dotm文件中的快捷方式偶尔会被删除,
所以我知道我可以通过单击单词(https://wordribbon.tips.net/T008058_Assigning_a_Macro_to_a_Shortcut_Key.html)
但是我想像在Excel中那样对它们进行硬编码:
Sub keyBoardShortCuts()
Application.OnKey "%^d", "updateDB"
Application.OnKey "%^p", "openProjectList"
Application.OnKey "%^m", "addNewLS"
Application.OnKey "%^l", "createLS"
Application.OnKey "%^g", "loadGui"
Application.OnKey "%^b", "Custom_Button_Click"
End Sub
Private Sub Workbook_Open()
Call keyBoardShortCuts
End Sub
然而,这在单词中不起作用,那么在单词中这样做的语法是什么?
答案 0 :(得分:2)
您需要使用KeyBindings
和Enum WdKey
中的常量(按F2查看列表):
With Application.KeyBindings
.Add KeyCode:=BuildKeyCode(wdKeyAlt, wdKeyControl, wdKeyD), _
KeyCategory:=wdKeyCategoryCommand, _
Command:="updateDB"
.Add KeyCode:=BuildKeyCode(wdKeyAlt, wdKeyControl, wdKeyP), _
KeyCategory:=wdKeyCategoryCommand, _
Command:="openProjectList"
.Add KeyCode:=BuildKeyCode(wdKeyAlt, wdKeyControl, wdKeyM), _
KeyCategory:=wdKeyCategoryCommand, _
Command:="addNewLS"
'...
End With 'Application.KeyBindings