Wednesday, September 5, 2012

Word Macro for analyzing dialog ratios in chapters

Here's a fun WORD macro for the writers out there.

Most of us are curious about how much of a chapter is dialog. You don't want it too thick with descriptions, and dialog is, lets face it, the juicy stuff that readers like. It's very useful to see what kind of dialog to text ratio there is, and this little gem does it.

Now, a few warnings.

First, you need to know how it defines a chapter. It looks at where the cursor is, then scrolls up until it finds a manual page break. If you don't separate your chapters this way, it won't work for you. It then scrolls down until it finds another manual page break. So, if you run it on the first chapter and there isn't a page break above or below where the cursor is, it'll get confused. Easy fix, just add a few manual page breaks and you're fine.

It'll get confused if you don't have any quotes in it at all. And, it'll report estimates, not exact word counts. So, just use it as a rough guideline, not an exact word counting tool.

Lastly, it doesn't understand what dialog is exactly, so it just counts the words that fall between two quotes. This works fine for most styles, but when your quotes go beyond a paragraph, it can confuse the poor thing.

Example: (I'll underline the dialog AS it Counts them)
Jack said, "Bla bla bla." And was slapped. Then he said, "Bla!"

It'll get that just fine.

Jack said, "Bla bla bla.
Bla bla bla
Bla bla bla." Jack got slapped. "But I bla bla
Bla bla bla"

It'll get that just fine.

Jack said, "Bla bla bla.
"Bla bla bla
Bla bla bla." Jack got slapped. "But I bla bla
"Bla bla bla"

This last style just confused the hell out of it. If this last style is how you do your quotes, it'll be useless to you. It's a valid style, but a nightmare to code it to be able to tell the difference between the two, so I had to pick one style. And, obviously, I picked my style.


It writes the report where your page number is. You probably don't know but that's the line below the text that reads something like this:

Page 1 Sec 1 1/1 At 4.3" Ln 18 Col 38

It's usually just above the word [Start]

The very next thing you do in word will erase the results and it'll return to the Page # thingy.


Now, if you manually edit the code, it can do some neat things. It can underline or bold all the dialog for you. That's sometimes very useful too.

======================================================

'
Sub ChapterOnlyReport()
'
' ChapterOnlyReport Macro This macro finds dialog in a chapter
' Macro recorded 6/26/2008 by TR NoWry And counts it, then reports at the end
' Chapters are defined by manual page brakes
' This lets you know how much of a chapter
' is dialog
'
UlDialog = False 'Change to True to Underline all the Dialog
BoldDialog = False 'Change to True to Bold all the Dialog
' 'Useful for diagnostics and, well, just fun!
On Error GoTo Quiter:
OEMpos = Selection.Start
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^m"
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Find.ClearFormatting
BeginChapter = Selection.Start
With Selection.Find
.Text = "^m"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Find.ClearFormatting
EndChapter = Selection.Start
ActiveDocument.Range(BeginChapter, EndChapter).Select
w1 = Int(Selection.Words.Count * 0.808)
WordNumber = Str(w1)
If Len(WordNumber) > 4 Then WordNumber = Left(WordNumber, Len(WordNumber) - 3) + _
"," + Right(WordNumber, 3)
Selection.Start = BeginChapter

Loop1:
With Selection.Find
.Text = """"
.Forward = True
End With
Selection.Find.Execute
If Selection.Find.Found = False Then GoTo OutLoop
If Selection.Start > EndChapter Then GoTo OutLoop
S1 = Selection.Start
With Selection.Find
.Text = """"
.Forward = True
End With
Selection.Find.Execute
If Selection.Find.Found = False Then GoTo OutLoop
If Selection.Start > EndChapter Then GoTo OutLoop
S2 = Selection.Start
ActiveDocument.Range(S1 + 1, S2).Select
w = w + Selection.Words.Count

'For pause = 1 To 6000000
'Next

ssold = Selection.Text
BG = 2.5
For pt = 1 To Len(ssold)
If Mid(ssold, pt, 1) = "," Or _
Mid(ssold, pt, 1) = ";" Or _
Mid(ssold, pt, 1) = """" Or _
Mid(ssold, pt, 1) = ":" Then BG = BG + 1
If Mid(ssold, pt, 1) = "," And pt = Len(ssold) - 1 Then BG = BG - 1
Next
w = w - BG

If BoldDialog Then Selection.FormattedText.Bold = True
If UlDialog Then Selection.FormattedText.Underline = wdUnderlineSingle

Selection.MoveRight
Selection.MoveRight
Selection.MoveRight

GoTo Loop1

OutLoop:
Selection.Start = OEMpos
Selection.End = OEMpos
For d = 1 To 15
Selection.MoveUp
Next
Selection.Start = OEMpos
Selection.End = OEMpos
Selection.MoveLeft

gg = ActiveDocument.Words.Count * 0.807
g = Str(Int(gg))
If Len(g) > 4 Then g = Left(g, Len(g) - 3) + _
"," + Right(g, 3)
WW = Str(Int(w))
If Len(WW) > 4 Then WW = Left(WW, Len(WW) - 3) + _
"," + Right(WW, 3)
StatusBar = "This Chapter has <<<-- " + WordNumber + " Words, " + """" + WW + """" _
+ ", or " + Str(Int((w / w1) * 100)) + "% in quotes -->>> " + g + " Total book"
Quiter:
End Sub

No comments:

Post a Comment