Helpful Macro

Fahim

Mad coder, lazy writer
Super Member
Registered
Joined
Jan 3, 2006
Messages
1,701
Reaction score
95
Location
Sri Lanka
Website
www.farook.org
This is pretty similar to the set of macros that Roger posted here (in the sticky thread at the top of the forum - if somebody missed 'em :p). In fact, the word list that my macro uses, comes from Roger's macros. I just don't like opening a separate document and then running a macro from that document on my document. So, I wrote my own Word macro which can be accessed directly from the current document and which highlights adverbs, passive words, overly used words and cliches/misused words. This one isn't as user-friendly as Roger's macro since the configuration goes into the macro code itself but hopefully you can figure it out :) It runs fairly fast since it completed a 90,000+ word document in about 30 seconds. But here's the code ... if anybody needs any help with it, just yell :)

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
 

Fahim

Mad coder, lazy writer
Super Member
Registered
Joined
Jan 3, 2006
Messages
1,701
Reaction score
95
Location
Sri Lanka
Website
www.farook.org
Oh yeah, if anybody doesn't know what to do with the above code, all you've got to do is 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.
 

jst5150

Vorpal Comics. Weekly Podcast. Twitch Artist. Vet
Kind Benefactor
Super Member
Registered
Joined
Sep 19, 2005
Messages
4,740
Reaction score
1,799
Location
Europe
Website
jasontudor.com
Excellent work. Thanks for this.
 

Mike Coombes

Guru
Super Member
Registered
Joined
Mar 6, 2005
Messages
774
Reaction score
58
Location
UK
Website
writers.ktf-design.com
Not wanting to appear stupid or anything... but wouldn't it be better to learn to write more competently, rather than relying on macros to make you look better?
 

Fahim

Mad coder, lazy writer
Super Member
Registered
Joined
Jan 3, 2006
Messages
1,701
Reaction score
95
Location
Sri Lanka
Website
www.farook.org
Mike, the macro's not going to automatically substitute words for you and hence, there really is no "making you look better" involved :) All it does is highlight what's already there in your document and point out patterns of usage. You can either take the suggestions and learn from them (hence learning to write more competently) or ignore them. Again, each individual's choice :)
 

Roger J Carlson

Moderator In Name Only
Super Member
Registered
Joined
Feb 19, 2005
Messages
12,799
Reaction score
2,499
Location
West Michigan
Mike Coombes said:
Not wanting to appear stupid or anything... but wouldn't it be better to learn to write more competently, rather than relying on macros to make you look better?
The usefulness of this macro (nice code, btw Fahim) and the utilities I created is that they highlight common writing problems which we often can't see on our own.

I got the idea for my first macro (Passive Word Highlighter) from my niece who is an English teacher. She will highlight every instance of "was" in a student's paper. I thought, "Hey, I could do that programmatically," and I did.

When you highlight passive or weak words, you discover how often you use them. It's a real eye-opener. (The first time I ran it against my book, I was appalled by the amount of red on the pages.)

The interesting thing about this process is that when you spend the time to edit these passive or over-used words and replace them with more robust words, you begin to use them less in your new writing. These utilities DO make you write mor competently..
 

Fahim

Mad coder, lazy writer
Super Member
Registered
Joined
Jan 3, 2006
Messages
1,701
Reaction score
95
Location
Sri Lanka
Website
www.farook.org
Roger J Carlson said:
(nice code, btw Fahim)

Thanks :) And thank you also for your suite of utilities - I'd been meaning to write an adverb highlighter macro for months now but didn't actually do it till I downloaded your utilities :p And as you might have noticed, I've borrowed your error handler, hope you don't mind :)
 

Roger J Carlson

Moderator In Name Only
Super Member
Registered
Joined
Feb 19, 2005
Messages
12,799
Reaction score
2,499
Location
West Michigan
Fahim said:
Thanks :) And thank you also for your suite of utilities - I'd been meaning to write an adverb highlighter macro for months now but didn't actually do it till I downloaded your utilities :p And as you might have noticed, I've borrowed your error handler, hope you don't mind :)
If I minded, I would have compiled it into a VB app where you couldn't see it. :)

I created the utilities as separate, external documents so people wouldn't have to figure out how to install them as Macros. I have dreams of someday creating a Word Add-in that will install into Word with its own toolbar that will run each program against the entire document or just selected text. Maybe someday.
 
Last edited by a moderator:

L M Ashton

crazy spec fic writer
Super Member
Registered
Joined
Mar 26, 2005
Messages
5,027
Reaction score
518
Location
I'm not even sure I know anymore...
Website
lmashton.com
Roger J Carlson said:
The usefulness of this macro (nice code, btw Fahim) and the utilities I created is that they highlight common writing problems which we often can't see on our own.
Ain't that the truth. Especially if you've been staring at it for months, or this is your fourth or tenth pass through editing. Ugh!
Roger J Carlson said:
When you highlight passive or weak words, you discover how often you use them. It's a real eye-opener. (The first time I ran it against my book, I was appalled by the amount of red on the pages.)
Same as when someone else marks your stuff up for errors. Or, at least, that's how it's supposed to work. (*cough* Fahim *cough*)

Roger J Carlson said:
The interesting thing about this process is that when you spend the time to edit these passive or over-used words and replace them with more robust words, you begin to use them less in your new writing. These utilities DO make you write mor competently..
Yup. Happens with all forms of active editing. As you replace your weak writing with something stronger, you begin to incorporate it into your first draft, and progressively, as long as you're working on improving your writing, your first drafts get better and better over time.

I'm working on a fourth first draft right now, and the writing is, by far, much stronger in this first draft than even my second after several rounds of editing. It really makes a difference in quality in the long run.

This is also, by the way, why I advocate critiquing other people's writing. It trains us to be able to spot errors easier, and after doing that to other people's writing, we begin to more easily see those same problems in our own writing. Critiquing is skewed in that respect - to me, it seems like the one giving the critique is in a position to benefit from giving the critique than the recipient has from getting it.
 

Fahim

Mad coder, lazy writer
Super Member
Registered
Joined
Jan 3, 2006
Messages
1,701
Reaction score
95
Location
Sri Lanka
Website
www.farook.org
Roger J Carlson said:
I created the utilities as separate, external documents so people wouldn't have to figure out how to install them as Macros. I have dreams of someday creating a Word Add-in that will install into Word with its own toolbar that will run each program against the entire document or just selected text. Maybe someday.

LOL. I know what you meant :) I wanted to make the editing of the configuration stuff easier and was looking into self-modifying VBA code ... but actually doing it will probably have to wait for another day ... Didn't even know you could compile it and create an Add-in - just don't use Word that much :p Guess I'll go look at that now for another macro I wrote which does have a GUI and where I couldn't figure out how to distribute it easily ...
 

Roger J Carlson

Moderator In Name Only
Super Member
Registered
Joined
Feb 19, 2005
Messages
12,799
Reaction score
2,499
Location
West Michigan
Fahim said:
LOL. I know what you meant :) I wanted to make the editing of the configuration stuff easier and was looking into self-modifying VBA code ... but actually doing it will probably have to wait for another day ... Didn't even know you could compile it and create an Add-in - just don't use Word that much :p Guess I'll go look at that now for another macro I wrote which does have a GUI and where I couldn't figure out how to distribute it easily ...
If you get it done, let me know. I'll steal your code then. :tongue
 

Fahim

Mad coder, lazy writer
Super Member
Registered
Joined
Jan 3, 2006
Messages
1,701
Reaction score
95
Location
Sri Lanka
Website
www.farook.org
Was checking the highlighting functionality for the macro under Word 2007 today and noticed a couple of issues. I don't know if the first issue was there under versions of Word before 2007, but the wildcard used to find adverbs seems to take more than a word at times. The other issue is that the adverb exception list is case-sensitive and so "Only", "only" and "ONLY" are treated as three different words :) I've fixed both but no guarantees as to whether the wildcard will work for any versions of Word other than Word 2007.

Here's what you need to do:

1. Add "Option Compare Text" on a line by itself before "Sub FAF_WordHighligher()" so it looks like this in the code in the first post:
Code:
Option Compare Text

Sub FAF_WordHighlighter()
'
' WordHighlighter Macro

2. Change the wildcard for adverb matching, which is currently "<[! ]@(ly)>" to "<[! ^13]@(ly)>" so that it looks like this in the code in the first post:
Code:
		With rng.Find
			.Text = "<[! ^13]@(ly)>"
			.Forward = True
 

Zelenka

Going home!
Super Member
Registered
Joined
Oct 1, 2007
Messages
2,921
Reaction score
488
Age
44
Location
Prague now, Glasgow in November
These all look so great. Unfortunately I seem to have something wrong with the installation of my MS Word, as I just keep getting an error message, something to do with the 'visual basic editor' not working. :(
 

Fahim

Mad coder, lazy writer
Super Member
Registered
Joined
Jan 3, 2006
Messages
1,701
Reaction score
95
Location
Sri Lanka
Website
www.farook.org
Have you tried repairing your Word installation? What version of Word do you have an what's your version of Windows?
 

Zelenka

Going home!
Super Member
Registered
Joined
Oct 1, 2007
Messages
2,921
Reaction score
488
Age
44
Location
Prague now, Glasgow in November
Have you tried repairing your Word installation? What version of Word do you have an what's your version of Windows?

I'm ashamed to say I'm still using Word 97 :eek: on Windows XP sp2. It seems to be something wrong with the installation disk itself as I've tried reinstalling and it comes up with the same error. I get an error message during installation, something to do with one of the driver files, and then the visual basic editor seems to be messed up somehow because of this.
 

Fahim

Mad coder, lazy writer
Super Member
Registered
Joined
Jan 3, 2006
Messages
1,701
Reaction score
95
Location
Sri Lanka
Website
www.farook.org
Hmm ... without knowing the exact error messages during installation, can't really help you much. But I do have a question? When you re-installed, did you install over your existing installation of Word? Or did you try uninstalling Word and then re-installing? Since it's Word 97, I can't recall if it had a repair feature but I suspect not :)
 

KarlaErikaCal

YA romance writer in love with love
Super Member
Registered
Joined
Sep 23, 2007
Messages
12,480
Reaction score
1,887
Location
Chicago
THANKS! It works perfectly! But after I ran it... I sure have loads to work on... Oh well
 

dgiharris

Disgruntled Scientist
Super Member
Registered
Joined
Aug 24, 2006
Messages
6,735
Reaction score
1,833
Location
Limbo
I developed a Spreadsheet for Tracking all of my short stories and articles. It is color coded. I created a generic template that shows how to use the spreadsheet. Within the spreadsheet, just put the cursor over any little red triangle (comments) and a pop-up window will show up with an explanation of the section.

On the bottom of the spreadsheet you will see different tabs for different sections.

I loaded the spreadsheet on an online file storage site: www.box.net

The user name is: dgiharris
email address is: [email protected]
password is: spreadsheet

it is in a folder titled AW spreadsheet (the only folder)

go there, download my excel file and enjoy

Mel...
 

writeaway

Super Member
Registered
Joined
Dec 11, 2009
Messages
119
Reaction score
5
Location
los angeles
I love this!!! I sent it to some writer friends who are published and they loved it. My only suggestion would be to put what each color means at the top of the document. i.e Turquoise (but use the color)= overused words etc... I know you can see it from the code, but everyone I sent it to was a complete computer novice, all that code scared them. They are not going to look at it. great job!
 

Gavin23

Dum Spiro, Spero.
Super Member
Registered
Joined
Aug 25, 2011
Messages
186
Reaction score
12
Found this really helpful, thanks :)