I would like to use punctuation to initiate and end a specific style in MS Word.

For example, I might type ` to use a particular style and also to end it `. My reason is actually exactly this, I want to use a different font for code fragments.

No 'answers' suggesting I learn and use LaTeX please. I want to shortcut styles in MS Word in this manner - would be useful in general too.

MS have this support page but it states 'start combinations with CTRL, ALT, or a function key'. Is there some other way? A macro? A plugin?


FWIW I suspect CharlieRB's link will be more useful, but...

You can associate styles with a single keystroke by using VBA, like this: (here "MyCStyle" is the name of a character style).

Sub setupMyCStyleKey()
' You should be able to set this up for a Template.
' Here, I set it up for the Active Document
CustomizationContext = ActiveDocument
KeyBindings.Add KeyCode:=BuildKeyCode(WdKey.wdKeyBackSingleQuote), _
  KeyCategory:=WdKeyCategory.wdKeyCategoryStyle, _
End Sub

' Sledgehammer
Sub ResetAllKeys()
CustomizationContext = ActiveDocument
End Sub

However, you will probably be better off starting using Back Single Quote, then finishing using ctrl-spacebar. Using the same key again does not toggle the style, and using any other key will just impose another style rather than "revert."

You can also associate a single key with a Macro using the same technique, and that might in principle let you set up the same key so that it acted as a toggle, but then you have to give some thought as to exactly how it is going to work (e.g., what if you click somewhere else in the document and type that key).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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