View Single Post
 
Old 06-26-2020, 01:28 AM
alex100 alex100 is offline Windows 7 64bit Office 2016
Advanced Beginner
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default

Thank you for your answer, Andrew!

I also found some helpful, step-by-step information in the following article:

VBA Express : Word - Add Keybinding to document to launch Macro

Anyhow, what I'm now using is the code below, and it works good! I inserted it in the 'ThisDocument' file, and it gets executed automatically when the document is opened (this was actually the main thing I was missing!).

Code:
Private Sub Document_Open()
    With Application
        .CustomizationContext = ThisDocument
        .KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyControl, wdKeyL), KeyCategory:=wdKeyCategoryCommand, Command:="MyScript1"
        .KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyAlt, wdKeyL), KeyCategory:=wdKeyCategoryCommand, Command:="MyScript2"
    End With
End Sub
Alex
Reply With Quote