2011-11-22 49 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,而不是編輯我的答案,然後向下投票,下次你只是發佈自己的答案?說接受的答案沒有用是不誠實的。 –

相關問題