Navigation Bar

HOME  |   ABOUT ME  |   MERM-8  |   DISNEY VILLAINS  |   VIDEO GAME MEMORIES  |   OTHER WORKS

Quote Generator



Monday, March 29, 2010

Macro 2: Find Sentences Longer than 20 words

UPDATE: This post has been amended.  You can find the complete list of writer's macros here.

Okay, here is the second one, and probably the 2nd most useful.  Word already has the ability to look for long sentences, but in today's age, long is a lot longer than you should have.  Especially if you're writing query letters or synopsisesises.  You can customize what the cut off is by altering the "maxWords" variable.

One of the most difficult things when developing these macros was determining when a sentence begins, when it ends, and how many words are inbetween.  Word claims to have native functions for this, but I found it quite often counting things like "," and ". ' " and "." as words when I was debugging.  So you'll find that snippet that only counts words that start with A-Z as words.  So far, this appears to be pretty accurate.

To use:
1. Copy the code below.
2. Open Word.
3. Press Alt+F8 (or go to Tools->Macro->Macros)
4. Click Edit. Microsoft Visual Basic will open.
5. In the project window (upper right), select Normal->Modules->NewMacros
6. Paste the code below into the text pane.
7. Click save and close the Microsoft Visual Basic.

'Finds sentences over 20 words long
Sub Find_Long_Sentences()
Application.Run MacroName:="Clear_All_Highlighting"

Dim totalWords As Integer
Dim maxWords As Integer

maxWords = 20
totalWords = 0

For Each mySentence In ActiveDocument.Sentences
For Each myWord In mySentence.words
SingleWord = Trim(LCase(myWord))
If SingleWord > "a" And SingleWord < "z" Then totalWords = totalWords + 1 End If Next myWord If totalWords > maxWords Then
mySentence.Select
Selection.MoveEnd Unit:=wdCharacter, Count:=-1
Selection.Range.HighlightColorIndex = wdPink
End If
totalWords = 0
Next mySentence

'Move cursor to beginning of document
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst

End Sub


Previous Macros:
Macro 1: Finding Questionable Words
Post a Comment