Mark Ward’s Microsoft Word Miracle Macro

Back in September of 2003 I had this problem, see. I would often paste text into Microsoft Word that included “straight quotes” instead of “smart (curly) quotes.” I didn’t like having to go through and change them to curly, so I set up a macro. All it did was find and replace all quotation marks; Word’s auto-correct feature did the rest.

Over time other common problems developed, so I added more code to what soon became my standard Word macro—kind of like an automatic diagnostic I use on nearly all documents.

I needed to do things like this:

  • Turn double hyphens (–) into em dashes (—).
  • Turn two concurrent spaces (  ) into one space ( ). (This is a problem created by old people who learned to type during typewriter days: they customarily place two spaces after every sentence-ending punctuation. This practice was helpful for legibility when every letter and character was set at a fixed width, but modern word-processing makes it obsolete.)
  • Turn em dashes with spaces around them (like — this) to em dashes with no spaces (like—this).
  • Turn hyphens between numerals (Matt 22:34-40) into en dashes (Matt 22:34–40). (This is something few people catch or care about, but it’s “best practice” among typographers and editors.)
  • Turn regular spaces into nonbreaking spaces in Scripture references such as “2 Sam.” (This is so one line doesn’t end with “2” and the next line start with “Sam.” Note: this only works if you use the standard SBL abbreviations.)
  • Fix the direction of curly quotation marks which are adjacent to other punctuation marks like dashes and ellipses.

To use the macro, close Word, open a blank Word document, hit Alt+F8, click “Edit,” and paste the full text of the macro (click here to download or click here to copy) into your macros list at the bottom. Hit the save button in Visual Basic, then close Word, agreeing to save changes to Normal.dotm.

Open a document in Word, then open your Macros (Alt+F8 in both Windows and Mac). You should now see at least one macro in the macro list, and this one is named “MarkWardsMicrosoftWordMiracleMacro.” Select that macro and click “Run.” The macro will run.

You can assign a button or keyboard shortcut to the macro by right-clicking on the toolbar, selecting “Customize Toolbars and Menus,” and choosing the Commands tab (this is for Mac, but the process is similar in Windows). Then select “Macros” under the Categories, then find the macro in the right-hand pane and drag it to a spot in your toolbar. Or click Keyboard > Categories > Macros and assign a new keyboard shortcut to the macro.

Author: Mark Ward

PhD in NT; theological writer for Faithlife; former high school Bible textbook author for BJU Press; husband; father; ultimate frisbee player; member of the body of Christ.

10 thoughts on “Mark Ward’s Microsoft Word Miracle Macro”

  1. Thanks, Mark. I copy-edit constantly and manually use the find-and-replace feature for most of the items you mention. But I’m hesitant to use this macro because it will change quotations. That is, if an author quotes another author who uses a different abbreviation (e.g., “Matt.” instead of “Matt”), then this macro would alter the quotation. No?

  2. If I’m following you correctly, the answer is no. It doesn’t change “Matt.” to “Matt.” It leaves the latter completely alone. It finds “Matt[space]” and replaces it with “Matt[non-breaking-space].”

    A user with your level of skill should probably read through the macro and understand each part before using it. For example, the way I do things, instances of “Mark” or “John” that are not actually Bible book names will have a non-breaking space added after them. That may make for an awkward line break with “John[nbs]Frame” on occasion, but watching for that and fixing it is easier than adding non-breaking spaces manually for all Scripture references.

    There is a better way to do this using regedit, I’m told, but it’s beyond my ken at this point. After the dissertation perhaps I’ll figure it out. Perhaps I’ll do a lot of things!

  3. Macros do work in the newest version of Office for Mac (2011), and I just tested these and they do work, but there appear to be some character encoding issues… For example a double dash (–) instead of becoming an em dash becomes accented o (ó). It’s probably a UTF-8 vs. ANSI something or the other issue. I’ll see what I can figure out…

  4. Thanks, other Andy! I’m glad to hear that, too, because there goes one of the four things that were keeping me from getting a Mac laptop next time. (The others are OneNote, BibleWorks, and money!)

  5. Ok, problems fixed… the issue w/ the double dash was a TextEdit issue, so I just copied the macro straight from Safari to Word’s macro editor. The other issue was that instead of a non-breaking space, I got a dagger symbol (like sometimes used with footnotes), so I changed all the occurrences of ^0160 (an ASCII code) to ^s which is a Word built-in code for a non-breaking space, and that worked great. Thanks Mark!

  6. Oh, as far as your other Mac issues, my Onenote replacement is Word’s notebook layout which does great with the auto-bulleting. The only disadvantage is its lack of ability to click anywhere to start a new text area. However, an added advantage is that my notes are more accessible/transferable, as I don’t have to export them to Word to share them with someone who doesn’t have Onenote.

    When Logos isn’t sufficient (which as I get better at Logos is less and less), I run Bibleworks in a virtual machine, but I don’t have an answer to the money issue. 😛

  7. I actually worked on this macro with Mark a good bit several months ago.

    The version I created is available here:
    https://gist.github.com/584122

    This includes some code that I was experimenting with that used regex. I never got that working though, so for now it’s commented out.

    If you use my version, it should work just like Mark’s original, only faster (if I correctly remember how things went when I was working with it).

    If anyone succeeds in implementing regex, please post it in the comments on my gist page.

  8. To be my curmudgeonly self, I like ’em’ dashes with spaces around them. And I hate en dashes in Bible references!

    On the verse references…

    Could you create a loop that goes something like this:

    Replace ‘Matt ^#’ with ‘~~^&’ [^# = any digit; ^& = Find What Text], then

    Replace ‘~~Matt ‘ with ‘Matt~~’, then

    Replace ‘~~’ with ‘^s’ [^s = non-breaking space]

    A little complicated, but should work… haven’t looked at your macro, so I don’t know exactly what the code looks like. Also, I don’t use the latest Word, so don’t know if the coding has changed (have I mentioned here how much I hate the Ribbon??).

    Anyway, regardless of changes, the concept should work if you tweak it a bit. My idea is to insert meaningless characters as markers for the text you want to change so that you avoid inadvertently putting a non-breaking space into a string where you don’t want it, as you suggested above.

    Maranatha!
    Don Johnson
    Jer 33.3

  9. Three find/replace calls for the verse refs would be a bit excessive, I think; but there are a few bits of that concept that would work OK. If I ever try to do a smart fix that only puts nbsp’s in Bible references I would use something other than find/replace, I think. This feature is something I should consider working into a new version of the code I’ve done already for Mark.

    FWIW, Word VBA works basically the same in Word 2007 and 2010 (although there are probably some new methods as well as a lot of bug fixes).

  10. Well, of course, I only do macros in a very workmanlike layman’s way. I’m waiting for you to get home and fix all my computer problems for me!

    Maranatha!
    Don Johnson
    Jer 33.3

Leave a Reply