Microsoft Office has long had a “smart quotes” feature, which turns simple ASCII quote characters into the curved quotation marks that most people find more aesthetically pleasing. For example:
This is a nice touch, if you’re writing prose. But if you’re writing about software development, those nice-looking curly quotes can render a line of source code syntactically incorrect. You take a working snippet of code, type it into a Word document to explain it, and now that code won’t run if a reader copies and pastes it into a program. Not good!
You can toggle Smart Quotes on and off through the Word UI, but it takes several steps to drill down into that setting, making that an inconvenient solution at best. In the past, whenever I’ve been writing a lot of developer-oriented content I would turn Smart Quotes off all the time, which avoids the copy & paste problem but makes other uses of quotes look crude.
I’ve recently gone to a much better approach: I wrote a simple macro to toggle that setting on and off, and now I can toggle between “optimized for code” and “optimized for prose” with a single keystroke.
Here’s how to set up a macro to toggle Smart Quotes on and off:
In Microsoft Word, click on the View tab, then click on the Macros dropdown and select Record Macro:
Give the macro a name, and assign it to a key (I used the F12 key, because I’ve never used its default action for Save As). Then press any key (doesn’t matter what you type here, because we’re going to delete it), and then select Stop Recording from the Macros dropdown.
We’ve now recorded a macro, and we’re going to replace its contents with a line of code that toggles the Smart Quotes setting.
Go back to the Macros dropdown and select View Macros. Click on the macro you’ve just recorded, then click Edit. In the window that pops up, delete all of the code and replace it with these three lines:
Sub togglequotes() Options.AutoFormatAsYouTypeReplaceQuotes = Not Options.AutoFormatAsYouTypeReplaceQuotes End Sub
It should look like this:
Click the X in the rop right corner to close that window and the one behind it, and your macros is saved and ready to use. You can now toggle between Smart Quotes and Dumb Quotes in a single keystroke!