![]() |
|
#2
|
||||
|
||||
|
I think you have a few options to determine the best approach.
All keybindings have a customisation context (which means the shortcut resides in a document, template or addin). So it shouldn't be difficult to enable/disable a template to change active keybindings. For instance, I would put your specific keybindings into an addin and then disable that addin to disable the keybindings. You could also add a GetKeyState to each of your macros so that when Ctrl, Shift or Alt is held down, an alternative path through your macro is taken (ie, do the built-in action instead) Another option might be to have a toggle switch on your ribbon that changes your keybindings. Sample code to change keybindings can be found here How to create hotKey in Word VBA (programatically)? - Stack Overflow Code that might help you along your path is below Code:
Sub GetBindings()
Dim aKB As KeyBinding
CustomizationContext = ActiveDocument.AttachedTemplate 'or ThisDocument
For Each aKB In KeyBindings
Debug.Print aKB.KeyString, aKB.Command ', aKB.CommandParameter, aKB.KeyCategory
'If aKB.KeyString = "Alt+B" Then aKB.Clear
''things you might want to explore
' aKB.Disable '' equivalent to clicking the Remove button in the Customize Keyboard dialog box
' aKB.Clear ''reset a built-in command to its default key assignment
' aKB.Rebind wdKeyCategoryCommand, "TestKeybinding"
' aKB.Execute
Next aKB
End Sub
'---------------------------------------------
Sub AddKeyBinding()
With Application
.CustomizationContext = ThisDocument
.KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyAlt, wdKey0), KeyCategory:=wdKeyCategoryCommand, Command:="TestKeybinding"
End With
End Sub
'---------------------------------------------
'Sub TestKeybinding() ' \\ Test sub for keybinding
' MsgBox "We have a winner", vbInformation, "Success"
'End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia Last edited by Guessed; 06-25-2024 at 11:42 PM. |
| Tags |
| disable macro, enable macro, toggle macro assignment |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Autosave toggle missing completely in Word
|
MikeyLasco77 | Word | 6 | 03-02-2023 07:08 AM |
| Word Refuses to Allow Macros, even when All Macros Enabled | devlon | Word VBA | 3 | 10-04-2022 02:15 PM |
MERGESEQ does not appear to be having a value assigned
|
gjone43 | Mail Merge | 6 | 10-15-2020 08:15 PM |
| vba editor - how to toggle the continuous display of all macros in a module | floattube | Word VBA | 0 | 11-28-2014 01:35 PM |
| Is there a way to toggle the contents that are displayed in a Word document? | sclind | Word | 1 | 02-24-2012 04:56 PM |