Skip to content

Instantly share code, notes, and snippets.

@eugrus
Last active May 22, 2025 00:49
Show Gist options
  • Save eugrus/39059aa4a538bd1ce2794c7be8bf84b0 to your computer and use it in GitHub Desktop.
Save eugrus/39059aa4a538bd1ce2794c7be8bf84b0 to your computer and use it in GitHub Desktop.
VBA for Word
Option Explicit
Dim myKey
' https://learn.microsoft.com/en-us/office/vba/api/word.keybindings.add
Private Sub Document_New()
KeyBindings_AddKey
End Sub
Private Sub Document_Open()
KeyBindings_AddKey
End Sub
Sub KeyBindings_AddKey()
CustomizationContext = ThisDocument
Set myKey = KeyBindings.Add( _
KeyCode:=BuildKeyCode(wdKeyTab), _
KeyCategory:=wdKeyCategoryCommand, _
Command:="TestKeyBindings" _
)
End Sub
Sub KeyBindings_Clear()
CustomizationContext = ThisDocument
myKey.Clear
End Sub
Sub TestKeyBindings()
MsgBox "Hello, world!", vbInformation, "KeyBindings Test"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment