Thread: Quote Hunter
View Single Post
Old 01-05-2008, 02:34 PM   #1
brewt
Boo-Frickety-Hoo-Erizer
brewt will become famous soon enoughbrewt will become famous soon enoughbrewt will become famous soon enoughbrewt will become famous soon enoughbrewt will become famous soon enoughbrewt will become famous soon enough
 
brewt's Avatar
 
Posts: 251
Karma: 686
Join Date: Oct 2007
Device: Kobo Glo HD!
Quote Hunter

I have been formatting some particularly bad files, and found something that just bugs me that I couldn't find another solution for. I would come across parts like this:

"She said, "All this Stuff."

or

She said, "All This Stuff.
Finishing her sentence on another line."


Quote marks were wrong. Word grammar checker couldn't spot it, Whitesmoke couldn't spot it, TextSpresso couldn't spot it. Guiguts could indicate quote mark problems, but it does it with line numbers - yuck. And it is darn tedious to have to actually read and proof for that on lots and lots of badly formatted files.

So it took me a while, but I managed to come up with a Word Visual Basic macro that would look for odd numbers of quote marks in a paragraph. It goes through the file from where you put the cursor, and stops on a paragraph with an odd number of double-quote marks. Solves a good percentage of the problem.

3 gotchas: It needs real [ ^p ] paragraphs (not [ ^l ]), I haven't hammered out the goofs caused by blank lines yet, and the end of the file puts it into a loop that one has to Ctrl-Break to get out of. If anyone cares to modify it, feel free.

I claim no responsibility for how it breaks things in your files. And there are other threads to show you how to import it into Word if you haven't done it before.


########################


Sub QuoteHunter()
'
' QuoteHunter Macro
' Macro recorded 12/26/2007 by bjc
'
'To find tedious formatting problems with quote marks.
'
ActiveDocument.UndoClear

Dim NumCharsBefore As Long, NumCharsAfter As Long, CountNoOfReplaces As Long

Top:

ActiveDocument.UndoClear
CountNoOfReplaces = 0
NumCharsBefore = 0
NumCharsAfter = 0
CountSelectionBefore = 0
CountSelectionAfter = 0


Selection.HomeKey Unit:=wdLine
Selection.GoTo What:=wdGoToBookmark, Name:="\Para"
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Extend
Selection.Find.ClearFormatting

CountSelectionBefore = Len(Selection)


With Selection.Find
.ClearFormatting
.Text = """"
.Replacement.ClearFormatting
.Replacement.Text = "~~" '
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.MoveRight Unit:=wdCharacter, Count:=1


'Get the number of chars AFTER doing Find & Replace
Selection.HomeKey Unit:=wdLine
Selection.GoTo What:=wdGoToBookmark, Name:="\Para"
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
CountSelectionAfter = Len(Selection)

'Calculate of the number of replacements,
CountNoOfReplaces = CountSelectionAfter - CountSelectionBefore

'Undo the replace
ActiveDocument.Undo
ActiveDocument.UndoClear

'Determine if the number of quotes is appropriate

If ((CountNoOfReplaces Mod 2) = 0) Then
' is even
Selection.EndKey Unit:=wdLine
Selection.Find.ClearFormatting
Selection.MoveRight Unit:=wdCharacter, Count:=1
GoTo Top

Else
' is odd
Response = MsgBox("Odd Number of Quotes in This Paragraph:" & Str$(CountNoOfReplaces) & " of them.", vbOKOnly)

End If

End Sub



########################



Enjoy.
-bjc
brewt is offline   Reply With Quote