View Single Post
 
Old 06-25-2020, 01:43 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 Assigning shortcut keys via a macro file

How do I assign a shortcut key to a MS Word subroutine?

I already know how to do it via the "Customize Ribbon" Options menu, but I'm interested in hardcoding the keys inside a macro file.

I understand I need to use something like the code below, but where exactly do I insert this code? I tried adding it to the 'ThisDocument' section, without any success.

Code:
With Application
    .CustomizationContext = ThisDocument
    .KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF1), _
    KeyCategory:=wdKeyCategoryCommand, _
    Command:="printAllRecords"
End With
source: VBA Word: how to call a function via shortcut key?

As an example, what I need is to call "MyScript1" subroutine when pressing Ctrl + L, and "MyScript2" subroutine when pressing Alt + L.

Alex
Reply With Quote