PDA

View Full Version : Solved: Assign shortcut key to style within macro?



clhare
03-23-2005, 11:37 AM
I have a macro that creates a couple styles. Is it possible to assign a shortcut key to the styles from within the macro?

I tried, but I don't see where I can designate the style that I want to give the shortcut to.

Any help is greatly appreciated!

Cheryl

hairywhiterabbit
03-23-2005, 03:36 PM
hi Cheryl,

The follow bit of code assigns the shortcut key "Alt+Shift+Crtl+z" to the Heading 1 style. It is defined in the Normal.dot file.

CustomizationContext = NormalTemplate
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyZ, _
wdKeyControl, wdKeyShift, wdKeyAlt), KeyCategory:=wdKeyCategoryStyle, _
Command:="Heading 1"

You should be able to assign your desired shortcut key to the new heading you have created. I would put a bit of error handling in so that the code doesn't fall over if your style, for whatever reason, doesn't get created.

Be careful you don't overwrite commonly used existing shortcut keys though!

Cheers,
Andrew

Anne Troy
03-23-2005, 03:42 PM
Ah. But you don't NEED a macro to assign a style to a shortcut key, unless you want that style and its shortcut key to travel with the document. Let me know...

Paleo
03-23-2005, 05:19 PM
Hi Anne,

can we create shortcuts for styles without using a macro? This interests me a lot, so can you tell me how?

I know I can press Ctrl + Shift + U and go to the styles, but how can I set a style by shortcut keys? Lets say a Heading 1?

Anne Troy
03-23-2005, 05:29 PM
Tools-Customize.

Choose Styles (all the way down on the left) and then hit the KEYBOARD button.

Click in Press a keystroke box.

Type the keystroke and hit Assign.

I like to use Alt+1 for heading 1, Alt+2 for heading 2, Alt+T for body text, Alt+G for graphic, Alt+B for bullet...etc.

Paleo
03-23-2005, 05:38 PM
Gee Anne,

I dont have that. I have clicked on Tools - Customize - Commands - Styles - Keyboard, but I dont have the headings styles there, only the normal.

What else should I do? I use Word 2003 with full installation and I do have the other styles on the document.

Anne Troy
03-23-2005, 05:45 PM
Wow. Never noticed that before. Better have a doc open that (at least) HAS used those styles once.

I just changed the same line of text to heading1, then 2, then 3. All then appear in that menu...

Paleo
03-23-2005, 05:50 PM
Hi Anne,

great, exactly. I created text using them and after that they showed there. Now I have attributed the shortcuts to them (copied yours :beerchug: ).

Thanks.

clhare
03-23-2005, 07:02 PM
Thanks Andrew! That's just what I needed. :thumb


Cheryl

Paleo
03-23-2005, 08:27 PM
Hi Cheryl,

if its solved please mark it solved by clicking on "Thread Tools" and selecting "Mark it solved"