如何在Word VBA中创建hotKey(以编程方式)?
标题是相当多我想要做一个便携式的热键,这意味着如果我贴字VBA代码 我仍然可以使用热键,如Excel的application.onkey
如何在Word VBA中创建hotKey(以编程方式)?
的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
非常感谢!它解决了我的问题结束代码:函数不能是私人的CustomizationContext = NormalTemplate KeyBindings.Add KeyCode:= BuildKeyCode(Arg1:= wdKeyControl,_ Arg2:= wdKeyT),KeyCategory:= wdKeyCategoryCommand,_ Command:=“funcname”' – Ben
很高兴听到这个工作。不要忘记接受答案。 –
嗨@DaveRook,而不是编辑我的答案,然后向下投票,下次你只是发布自己的答案?说接受的答案没有用是不诚实的。 –
什么是代码? – JimmyPena