2011-11-22 55 views

回答

5

KeyBindings对象的东西应该做的问题

诀窍。在这里看到一个例子:http://www.vbaexpress.com/kb/getarticle.php?kb_id=621

' \\ Code for Module1 
Option Explicit 

Sub AddKeyBinding() 
    With Application 
     ' \\ Do customization in THIS document 
     .CustomizationContext = ThisDocument 

     ' \\ Add keybinding to this document Shorcut: Alt+0 
     .KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyAlt, wdKey0), _ 
     KeyCategory:=wdKeyCategoryCommand, _ 
     Command:="TestKeybinding" 
    End With 
End Sub 

' \\ Code for Module2 
Option Explicit 

' \\ Test sub for keybinding 
Sub TestKeybinding() 
    MsgBox "We have a winner", vbInformation, "Succes" 
End Sub 
+0

非常感谢!它解决了我的问题结束代码:函数不能是私人的CustomizationContext = NormalTemplate KeyBindings.Add KeyCode:= BuildKeyCode(Arg1:= wdKeyControl,_ Arg2:= wdKeyT),KeyCategory:= wdKeyCategoryCommand,_ Command:=“funcname”' – Ben

+0

很高兴听到这个工作。不要忘记接受答案。 –

+0

嗨@DaveRook,而不是编辑我的答案,然后向下投票,下次你只是发布自己的答案?说接受的答案没有用是不诚实的。 –

相关问题