MS Word macro for subscript/superscript formatting

Mel Starrs has just posted a handy time-saving tip over at Elemental which explains how to use MS Word’s autocorrect feature to ensure that your CO2 subscript always comes out right. It’s a handy approach and saves your work from the annoying critic who ignores your carefully crafted argument while pointing out every last formatting error.

My contribution here is from the point of view of someone who edits quite a lot of other people’s reports as well as writing my own, in which case you can’t rely on the autocorrect method. Instead I hunted around on the net for a way of correcting it automatically using a macro. Eventually I found what I was looking for on G Mayor’s site . It needed a bit of adaptation to do exactly what I wanted but it’s now a real time saver. It covers:

  • m2
  • m3
  • R2
  • CO2
  • NO2
  • SO2
  • H2O

Just download and unzip the file from the link below, then import it to your Normal template in MS Word.

FormatFormulae.

To add the macro to the Normal template open up MS Word and press Alt-F11 to open the VBA editor window —>  Ctrl-R to show the project explorer (if it isn’t already showing) —> right click the Normal template —> Import file —> browse for the FormatFormulae.bas file —> Open, and you’re done.

It’s so handy that I also decided to add it to the Quick access bar for easy access (MS Word 2007 and 2010 only).

To add a button to the Quick Access Toolbar in MS Word 2010, first click on the down arrow at the right hand end of the row of icons that includes the Save icon, then select More commands —> Choose commands from —> Macros. Then find Normal.FormatFormulae.CommonFormulae in the list that appears and use the Add >> button to move it across to the Quick Access Toolbar.

Next you can add an icon so you can find it easily. I’ve hijacked the π symbol which normally serves as the insert formula button but you can add whatever makes sense to you. Just click Modify and select an icon from the options that appear.

If you’re confident messing about with VBA for Word, the code is commented to show you how to adapt it to cover any other subscript/superscript formulae that you use regularly.

Edit: A macro which does the same kind of thing, plus fixes some common typos (KWh for kWh, etc.) for Excel is now available here.

3 Responses to MS Word macro for subscript/superscript formatting

  1. Richard Hawkins says:

    Amazing!

    I’m assuming this won’t work for Mac Office though… :o (

  2. Harold says:

    This is amazing tips!

    I have over 500 CO2!

    Great help for me.

    Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>