Useful Word Macros

Macros let you do repetitive tasks in Word quickly, which is a real blessing for large copyediting projects and workflows with predictable tasks. The following are a handful of macros that have greatly reduced the tedium and increased the accuracy of editing jobs that I've done. There are plenty of good resources online for how to record original Word macros, but the following can be installed quickly by pasting them right into Word's macro code window. Of course, the biggest gains to sanity and productivity come from setting up keyboard shortcuts to run these macros from the keyboard.

Toggling Tracked Changes

When editing with track changes in Microsoft Word, I frequently switch back and forth between the "Final Showing Markup" and the "Final" views, so that I can quickly preview the final copy. I also frequently turn track changes on and off as I edit, so that formatting changes don't clutter the document with extraneous markup. A big time saver is this macro, which changes both the track changes status and the view status simultaneously:

Sub toggle_tracked_changes()
'
' This marcro turns on and off track changes and switches
' the current document view to match.
'

ActiveDocument.TrackRevisions = Not ActiveDocument.TrackRevisions
     With ActiveWindow.View
    .ShowRevisionsAndComments = ActiveDocument.TrackRevisions
End With
End Sub

Replacing Hypens with En Dashes

This macro helps find where en dashes could be placed throughout a document. Each time the macro is run, it finds the next occurrence of a hyphen between two numbers and replaces it with an en dash. This macro should be run carefully and iteratively through a document, because there are plenty of instances where a hyphen belongs between two numbers (in ZIP codes, section numbers, and telephone numbers, for instance). The macro is written so that if it changes what should be a hyphen into a dash, you can quickly hit "Undo" to fix it, run the macro again, and move on to the next cadidate.

Sub endash_check()
'
' This macro searches for the next instance of a hyphen character
' between two numbers. It then replaces the hyphen with an en dash.
'

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
    .Text = "^#-^#"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With

If Selection.Find.Execute Then
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.TypeText Text:="–"
End If

End Sub

General Text Cleanup

This macro cleans up a bunch of common copy problems all at once, including removing superfluous spaces, replacing instances of "--" with proper em dashes, replacing "straight quotes" with “curly quotes,” and removing extra spaces at the end of paragraphs. This is a good macro to run before you begin copyediting a piece, since these types of issues have a tendency to repeat constantly throughout documents.

Sub cleanup()
'
' This macro performs general text cleanup, including:
' * deleting all instances of more than one space
' * replacing any instances of "--" with em dashes
' * removing all spaces from before paragraph marks
' * resetting all quotes and apostrophes, to ensure proper curly quotes
'
Selection.Find.ClearFormatting
With Selection.Find
     .Text = "  "
     .Replacement.Text = " "
     .Forward = True
     .Wrap = wdFindContinue
     .Format = False
     .MatchCase = False
     .MatchWholeWord = False
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
End With

While Selection.Find.Execute
     Selection.Find.Execute Replace:=Word.WdReplace.wdReplaceAll
Wend

With Selection.Find
     .Text = "--"
     .Replacement.Text = "—"
     .Forward = True
     .Wrap = wdFindContinue
     .Format = False
     .MatchCase = False
     .MatchWholeWord = False
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
End With

Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
     .Text = " ^p"
     .Replacement.Text = "^p"
     .Forward = True
     .Wrap = wdFindContinue
     .Format = False
     .MatchCase = False
     .MatchWholeWord = False
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
End With

While Selection.Find.Execute
     Selection.Find.Execute Replace:=Word.WdReplace.wdReplaceAll
Wend

With Selection.Find
     .Text = """"
     .Replacement.Text = """"
     .Forward = True
     .Wrap = wdFindContinue
     .Format = False
     .MatchCase = False
     .MatchWholeWord = False
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
End With

Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
     .Text = "'"
     .Replacement.Text = "'"
     .Forward = True
     .Wrap = wdFindContinue
     .Format = False
     .MatchCase = False
     .MatchWholeWord = False
     .MatchWildcards = False
     .MatchSoundsLike = False
     .MatchAllWordForms = False
End With

Selection.Find.Execute Replace:=wdReplaceAll

End Sub