View Full Version : Add Keyboard Shortcuts to Styles Using VBA?
clhare
11-23-2010, 06:39 AM
Is it possible to assign shortcut keys to styles using VBA? We are replacing styles with new styles and some style names will be changed. I tried assigning the same shortcut keys to the new styles but find that when the new styles are added to the document, the shortcut keys I assigned to them are no longer there. I think that's because the original styles (with those shortcuts) are still in the document. I have to replace the old style with the new style before removing the old style.
So, I'm hoping there's a way to add the shortcuts as the last part of the macro.
fumei
11-24-2010, 09:59 AM
"but find that when the new styles are added to the document, the shortcut keys I assigned to them are no longer there. "
What do you mean by the enw styles are added to the document?
Ketboard shortcuts are document specific.
Paul_Hossler
11-24-2010, 10:07 AM
One way that seems to work ok
1. In the appropriate Open event or in the last part of the appropriate macro
CustomizationContext = ActiveDocument
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyControl, wdKeyShift, wdKeyT), _
KeyCategory:=wdKeyCategoryStyle, Command:="Title"
Control-Shift-t will apply the 'Title' style to the current paragraph
Paul
(edited to pastein correct bit of VBA)
fumei
11-24-2010, 10:33 AM
Cheryl, please note Paul's line:
CustomizationContext = ActiveDocument
As stated, keyboard cshortcuts are document specific. CustomizationContext is one of: NormalTemplate, AttachedTemplate or ActiveDocument.
" I have to replace the old style with the new style before removing the old style."
Would that not remove the new style (since it replaced the old style)?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.