Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know how to assign shortcut keys to Styles. But what I would like to do is create a shortcut key that functions like the Bold/Italic/Underline keys (Ctrl-B/Ctrl-I/Ctrl-U): Namely, when I hit the shortcut key, I want the associated style to be toggled ON; then when I het the shortcut key again, I want the style to toggle OFF. Is there a way to make this happen?

I have set up a style that I use often (sporadically throughout a document), so I want to be able to turn it on and off quickly from the keyboard as I type. (The current behavior is that I have to type my text, then go back and select the text that I want to apply the style to, then hit the shortcut key.)

NOTE: A satisfactory alternative would be the ability to assign a Shortcut Key to the "Default Paragraph Font" (so I could have one key to turn the special style on, then another to turn it off -- currently you can't do this without using the mouse.) Unfortunately, that appears to be the one style that you can't assign a shortcut to. (*sigh*)

share|improve this question
up vote 1 down vote accepted

I figured out two ways:

1) use Ctrl+space to clear formatting (answering the alternative above), or

2) create the following VBA macro, and assign it to a shortcut key:

If Selection.Style = "KM_Code_ch" Then
    Debug.Print ("toggling off")
    Selection.Font.Reset
Else
    Debug.Print ("toggling on")
    Selection.Style = ActiveDocument.Styles("KM_Code_ch")
End If

(Note: this of course only works with character styles, not paragraph styles.)

share|improve this answer

I don't know a way of setting your shortcut key to a toggle aside from the VBA macro already suggested.

The best alternate option here is control+shift+n which sets the style to "Normal", so you can use the shortcut key you've setup for your own style, then press control+shift+n to return to "normal" style.

The suggestion of control+space actually only strips additional formatting (eg bold or underline) that you've added, and reverts the selected text to it's original style (whether the style was "Normal", or "Heading 1" or whatever), so it won't do what you want.

If your style is one you will only use on individual lines (eg like a heading style), then when setting up (or modifying) the style, you can set the "Style for following paragraph" to revert to "normal" (or any other style - you could modify heading 1, to go to heading 2 for the following paragraph if you wanted to always add a sub-heading after a heading, which would then revert to Normal unless you modified heading 2 to do otherwise).

I agree with the OP though, it would be great if setting the keystroke as a toggle was an option when creating it!

share|improve this answer
    
Welcome to SuperUser, Quentin! Glad to have you. I'm afraid your suggestion (Ctrl-Shft-n) doesn't seem to work in my experimentation. At least, not reliably. For now I'll stick with my macro. Thanks anyways! – kmote Jun 2 at 15:28

If you hit the shortcut that applies the style AGAIN it toggles the style off. So, for example, Ctrl-B turns bold on, then Ctrl-B again turns it off.

share|improve this answer
    
Yes, I was aware of this feature, but it only works on the Bold/Italic/Underline styles. I was looking for the same functionality on ALL user-defined styles. Thanks anyways. – kmote Feb 19 '13 at 16:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.