Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 06-25-2024, 05:27 PM
Guessed's Avatar
Guessed Guessed is offline toggle macros assigned to key in Word 365 Windows 10 toggle macros assigned to key in Word 365 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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.
Reply With Quote
 

Tags
disable macro, enable macro, toggle macro assignment



Similar Threads
Thread Thread Starter Forum Replies Last Post
toggle macros assigned to key in Word 365 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
toggle macros assigned to key in Word 365 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:30 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft