How to selectively count words in Word based on highlight color
March 7, 2011 11:26 AM Subscribe
I've got a text in Word with highlighting in two colors. Is there a way to delete all the text with highlighting in only one of those colors?
I've got a Word text with sentences highlighted in two different colors, thoroughly interspersed. I'm trying to find a shortcut way to get a word count for text that is highlighted only one of those colors, without going through on a scratch copy and deleting everything in the other color by hand. I can do a find-and-replace operation to delete non-highlighted text, but there appears to be no way to delete selectively, based on actual highlighting color.
Ideas?
I've got a Word text with sentences highlighted in two different colors, thoroughly interspersed. I'm trying to find a shortcut way to get a word count for text that is highlighted only one of those colors, without going through on a scratch copy and deleting everything in the other color by hand. I can do a find-and-replace operation to delete non-highlighted text, but there appears to be no way to delete selectively, based on actual highlighting color.
Ideas?
Best answer: You want to create a Macro. Open the document, then from the toolbar, Tools -> Macro -> Macros -> Create
Here's the VBScript for a macro you can create that will tell you how many words are highlighted yellow:
You will want to change wdYellow to whatever color you used to highlight. Here's a list of the default colors.
posted by trueluk at 12:33 PM on March 7, 2011 [3 favorites]
Here's the VBScript for a macro you can create that will tell you how many words are highlighted yellow:
Sub countWordsHighlightedYellow() Dim highlightCount highlightCount = 0 For Each w In ActiveDocument.Words If w.HighlightColorIndex = wdYellow Then 'w.Delete highlightCount = highlightCount + 1 End If Next MsgBox ("There are " & highlightCount & " words highlighted yellow.") End SubIf you want to delete the words that are highlighted (yellow) then uncomment w.Delete.
You will want to change wdYellow to whatever color you used to highlight. Here's a list of the default colors.
posted by trueluk at 12:33 PM on March 7, 2011 [3 favorites]
You don't need to use a macro. Just hit ctrl-f, format highlighted (choose whatever color), and select find all. Then click word count.
posted by prefpara at 2:51 PM on March 7, 2011
posted by prefpara at 2:51 PM on March 7, 2011
That doesn't work, prefpara, because there is no way to search for a particular highlight color. You can search for things that are highlighted, or not highlighted, but not for a particular color.
posted by kindall at 3:11 PM on March 7, 2011 [1 favorite]
posted by kindall at 3:11 PM on March 7, 2011 [1 favorite]
Response by poster: You guys are great! I used trueluk's script and it worked perfectly (and also gives me the option of not only counting, but also deleting--useful if I not only needed to count, but needed to create a file containing only the text highlighted in color X).
posted by drlith at 8:43 AM on March 8, 2011
posted by drlith at 8:43 AM on March 8, 2011
This thread is closed to new comments.
posted by kindall at 11:49 AM on March 7, 2011