本文介绍了如何在Word VBA中(以编程方式)创建hotKey?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
标题几乎是个问题
我想制作一个便携式热键,这意味着如果我粘贴单词vba code我仍然可以使用该热键,例如Excel的application.onkey
I want to make a portable hotkey, meaning if I paste the word vba codeI can still use that hotkey, something like Excel's application.onkey
推荐答案
KeyBindings
对象应该可以解决问题.在此处查看示例: http://www.vbaexpress.com/kb/getarticle. php?kb_id = 621
The KeyBindings
object should do the trick. See an example here: 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
这篇关于如何在Word VBA中(以编程方式)创建hotKey?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!