Hatrack River Writers Workshop   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Writers Workshop » Forums » Open Discussions About Writing » helpful macro for MS Word

   
Author Topic: helpful macro for MS Word
quidscribis
Member
Member # 2240

 - posted      Profile for quidscribis           Edit/Delete Post 
Fahim (my husband) has written a macro which can be accessed directly from the current document and which highlights adverbs, passive verbs, overly used words and cliches/misused words. It runs fairly fast - completed a 90,000+ word document in about 30 seconds.

To use, open Word, go to Tools - Macro - Macros ... and click on the Create button. This should open up the macro editor. Simply copy the above code, paste it in and click the Save button and then close the Macro Editor. You should be done When you want to run it, you go back to Tools - Macro - Macros ... select the FAF_WordHighlighter macro and click the Run button - it will process the currently open document.

code:
  
Sub FAF_WordHighlighter()
'
' WordHighlighter Macro
' Highlight specific types of words in current document
On Error GoTo Err_HighlightWords

Dim adverbExList
Dim passiveList
Dim overusedList
Dim clicheList
Dim adverbColor As WdColorIndex
Dim passiveColor As WdColorIndex
Dim overusedColor As WdColorIndex
Dim clicheColor As WdColorIndex
' *** Modify the following section to configure ***
adverbExList = Array("only", "oily", "family", "homily", _
"Billy", "Sally", "multiply", "imply", "gangly", _
"apply", "bully", "belly", "silly", "jelly", "holy", _
"lovely", "holly", "fly", "July", "rely", "reply", _
"Lilly", "sully", "gully" _
)
adverbColor = wdYellow
passiveList = Array("is", "isn't", "am", "are", "aren't", "was", _
"wasn't", "were", "will", "would", "won't", "has", _
"had", "have", "be", "been", "do", "don't", _
"did", "didn't", "does", "doesn't", "by", "being" _
)
passiveColor = wdPink
overusedList = Array("seem", "seems", "exist", "exists", "appears", _
"make", "makes", "show", "shows", "occur", "occurs", "get", _
"got", "went", "put", "some", "many", "most", "that", "very", _
"extremely", "totally", "completely", "wholly", "utterly", _
"quite", "rather", "slightly", "fairly", "somewhat", _
"suddenly", "all of a sudden" _
)
overusedColor = wdTurquoise
clicheList = Array("kind of", "sort of", "the reason for", _
"past history", "this is why", "end result", _
"it is possible that", "the possibility exists", _
"for all intents and purposes", "there is a chance that", _
"is able to", "has the opportunity to", "past memories", _
"future plans", "sudden crisis", "terrible tragedy", _
"as a matter of fact", "quite frankly", "all the time", _
"white as a sheet", "as soon as possible", "at the very least", _
"down in the dumps", "in the nick of time", "hat in hand", _
"keep your mouth shut", "made a run for it" _
)
clicheColor = wdBrightGreen
' *** do not modify code beyond this if you don't know what you're doing ***

'variables
Dim word
Dim rng As Range
Dim excluded As Boolean
Dim story As WdStoryType
Dim oldTrack
Dim oldHighlight
' Save current settings
oldTrack = ActiveDocument.TrackRevisions
oldHighlight = Options.DefaultHighlightColorIndex
ActiveDocument.TrackRevisions = False
' Iterate through each document section
For Each rng In ActiveDocument.StoryRanges
' Work only with the main body, footnotes and endnotes
story = rng.StoryType
If story <> wdMainTextStory And story <> wdFootnotesStory And story <> wdEndnotesStory Then
GoTo NextRange
End If
' Do the adverb highlighting
rng.Find.ClearFormatting
rng.Find.Replacement.ClearFormatting
With rng.Find
.Text = "<[! ]@(ly)>"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While rng.Find.Execute(Replace:=wdNone) = True
If rng.Text = "" Then
Exit Do
End If
excluded = False
For Each word In adverbExList
If rng.Text = word Then
excluded = True
Exit For
End If
Next
If Not excluded Then
' Highlight current selection
rng.HighlightColorIndex = adverbColor
End If
Loop
' Obtain range again
Options.DefaultHighlightColorIndex = passiveColor
rng.WholeStory
' Set rng = ActiveDocument.StoryRanges.Item(story)
' Do passive word highlighting
rng.Find.ClearFormatting
rng.Find.Replacement.ClearFormatting
rng.Find.Forward = True
rng.Find.Wrap = wdFindContinue
rng.Find.Replacement.Highlight = True
rng.Find.Format = True
rng.Find.MatchCase = False
rng.Find.MatchWholeWord = True
rng.Find.MatchWildcards = False
rng.Find.MatchSoundsLike = False
rng.Find.MatchAllWordForms = False
For Each word In passiveList
rng.Find.Text = word
rng.Find.Execute Replace:=wdReplaceAll
Next
' Do overused word highlighting
Options.DefaultHighlightColorIndex = overusedColor
rng.WholeStory
For Each word In overusedList
rng.Find.Text = word
rng.Find.Execute Replace:=wdReplaceAll
Next
' Do misused word/cliche highlighting
Options.DefaultHighlightColorIndex = clicheColor
rng.WholeStory
For Each word In clicheList
rng.Find.Text = word
rng.Find.Execute Replace:=wdReplaceAll
Next
NextRange:
Next
' Restore saved settings
ActiveDocument.TrackRevisions = oldTrack
Options.DefaultHighlightColorIndex = oldHighlight
MsgBox "Word highlighting complete!"
Exit Sub
Err_HighlightWords:
MsgBox Err.Description
End Sub


If you have any problems, you can post it here or on Fahim's forum or email Fahim directly at fahimf at gmail dot com.

I hope you enjoy!

[This message has been edited by quidscribis (edited January 26, 2006).]


Posts: 83 | Registered: Nov 2004  |  IP: Logged | Report this post to a Moderator
rcorporon
Member
Member # 2879

 - posted      Profile for rcorporon   Email rcorporon         Edit/Delete Post 
Don't mean to be rude, but I think I heard once that macro's could contain viruses?

I'm not trying to say that this is what you are doing here at all, so please don't be offended! Just trying to be safe.


Posts: 450 | Registered: Sep 2005  |  IP: Logged | Report this post to a Moderator
quidscribis
Member
Member # 2240

 - posted      Profile for quidscribis           Edit/Delete Post 
Yep, macros can contain viruses.

The code is provided - nothing's hidden. Take a look at it. If you don't understand it, then ask someone else who you trust to look at it.

If you don't trust it, then don't use the macro.


Posts: 83 | Registered: Nov 2004  |  IP: Logged | Report this post to a Moderator
yanos
Member
Member # 1831

 - posted      Profile for yanos   Email yanos         Edit/Delete Post 
What is a passive word? I know what a passive sentence is and I know what passive voice is, but a passive word...
Posts: 575 | Registered: Dec 2003  |  IP: Logged | Report this post to a Moderator
quidscribis
Member
Member # 2240

 - posted      Profile for quidscribis           Edit/Delete Post 
It would be a typo.
Posts: 83 | Registered: Nov 2004  |  IP: Logged | Report this post to a Moderator
Survivor
Member
Member # 213

 - posted      Profile for Survivor   Email Survivor         Edit/Delete Post 
Just a question, I'm not familiar with word macro coding...does this save all that
highlighting to the document? It doesn't look like it does, but I want to ask (for
the benefit of anyone actually trying this out).

Also, special attention to the *** Modify the following section to configure ***
part. If you want to add exceptions to the adverb flagging or whatever, you can do it
there.


Posts: 8322 | Registered: Aug 1999  |  IP: Logged | Report this post to a Moderator
quidscribis
Member
Member # 2240

 - posted      Profile for quidscribis           Edit/Delete Post 
I'll ask Fahim in the morning. He's sound asleep while I'm stuck in insomnia hell.
Posts: 83 | Registered: Nov 2004  |  IP: Logged | Report this post to a Moderator
quidscribis
Member
Member # 2240

 - posted      Profile for quidscribis           Edit/Delete Post 
If you use the macro, it doesn't actually save the changes until you click on Save. If you try to close the document after running the macro but not saving, it will prompt you to save. If you say No, then the highlighting will not be saved.

Clear as mud?


Posts: 83 | Registered: Nov 2004  |  IP: Logged | Report this post to a Moderator
Survivor
Member
Member # 213

 - posted      Profile for Survivor   Email Survivor         Edit/Delete Post 
Seems clear enough. That's what I thought it said, but I don't use Word so I wouldn't know for sure.

So, for a long document that you'll be editing for several sessions, you can open it, run the macro, save under a different filename, and you're original document should be unaffected.


Posts: 8322 | Registered: Aug 1999  |  IP: Logged | Report this post to a Moderator
quidscribis
Member
Member # 2240

 - posted      Profile for quidscribis           Edit/Delete Post 
Yup.
Posts: 83 | Registered: Nov 2004  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2