June 13, 2013

A Macro for Line-Editing in Microsoft Word

Today at Gem State Writers, I'm talking about the What, Why, and How of Line Edits.

But here, I wanted to share (with permission) the excellent tool my husband programmed to assist with line edits.  He watched me spending hour after hour using CTRL+F to go through my list of potentially problematic line edit word list...and then programmed a button into Word that instantly highlights every one of these.

Line edits went much, much faster.  Here's the technical bits:

The list of words is easily customized.  It is a Visual Basic Applications script so it should work with all versions of Word, though how to set it up will be different for newer versions of Word. On the new version the Visual Basic Editor is in Developer tab.


To Start: On the Word menu, go to Tools, then Macros. Then go to the Visual Basic Editor. The default module should be open. You can go down to the bottom of that module or start a new one to put in this new subroutine. To use just place in the Array() in quotes any word that you wish to highlight. The highlighted words are in yellow, but changing the color is easy -- wdRed, for instance, to make it red.

MatchWholeWord is set to true so it will highlight only if it is the whole word.  This means the list needs "was" and "wasn't" for both to highlight, but words like "wash" won't highlight.  This can be set to False instead.  Here is the macro:

Sub LineEdits()

Dim range As range
Dim i As Long
Dim TargetList 

TargetList = Array("was", "were", "just", "very", "only", "really", "started", "began", "even", "able", "think", "wasn't")

For i = 0 To UBound(TargetList)

Set range = ActiveDocument.range

With range.Find
.Text = TargetList(i)
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

Do While .Execute(Forward:=True) = True
range.HighlightColorIndex = wdYellow
Loop
End With
Next

End Sub

To use this macro,  click Tools, Macro, Macros, and then run LineEdits.  The highlighted text can be changed like any normal highlighted text.

To make a Line Edit shortcut button on the toolbar, in Word 2003, right click on the toolbar, select Customize, then select the tab Commands. In that tab scroll down to Macros. Once you select macros the name of your subroutine will appear as something similar to: (Normal.Module1.LineEdits); select it and drag and drop it on to the toolbar where you want it to appear. You will now have a button with the long and ugly label: (Normal.Module1.LineEdits). To rename it right click again on the toolbar and select Customize, then right click on the button and change the name field to what ever you want, such as LineEdits.

This macro was created with the help of Stack Exchange.

Lots of thanks to my awesome husband for creating this and sharing!

2 comments:

  1. Hi MK...is there a way to turn it off?

    ReplyDelete
  2. I just select the whole document (CTRL+A), then click the "no highlight/background color" for text. So...I guess there isn't, but if you don't have other highlighted text in the document, it's easy to remove the highlighting.

    ReplyDelete