Checking for Missing Quotation Marks

by Allen Wyatt
(last updated November 1, 2014)

6

David is a writer and he uses Word's spelling, style, and grammar checkers a lot. Sometimes he finds that Word's suggestions, for correcting grammar, are bad and he has learned to ignore them. One thing that he has trouble with is the use of quotation marks around dialogue. Word doesn't recognize if David has left off a quotation mark at the end or beginning of a sentence. He remembers using a word processing program years ago that left green quotation marks on your document to indicate a missing quotation mark. He wonders if Word can be made to recognize missing quotation marks.

There is no way to do this natively within Word. The reason probably boils down to the fact that it is almost impossible to determine where a quote should begin and end. For instance, if you have a paragraph that contains four sentences and you place a quote mark somewhere within that paragraph, how is Word to determine whether that mark designates the beginning or end of a quote? If it is the beginning, how would Word know if the ending mark should be at the end of the sentence, the end of the second sentence, or the end of the paragraph? (The same conundrum occurs if the quote is the ending quote, but the placement perplexity extends to the left instead of the right.)

Combine this potential confusion with the fact that the closing quote mark might not even be in the current paragraph—it could be at the end of some later paragraph when the dialog being marked actually ends.

You could, however, develop a macro that would do at least some elementary checking for you. The following macro jumps to the beginning of the document and searches for the first quote mark. It then examines everything from that character to the end of the paragraph. If you are using non-smart quotes, it basically checks to see if there are an even number of quote marks. If you are using smart quotes, then it checks to see if there is an ending quote for each starting quote. If either condition is found to be false, then the text is highlighted.

Sub MarkUnevenQuotes()
    Dim sRaw As String
    Dim iNorm As Integer
    Dim iSmart As Integer
    Dim J As Long

    Selection.HomeKey Unit:=wdStory
    Application.ScreenUpdating = False
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = """"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute

    While Selection.Find.Found
        Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
        Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
        sRaw = Selection.Text
        iNorm = 0
        iSmart = 0
        For J = 1 To Len(sRaw)
            If Mid(sRaw, J, 1) = Chr(34) Then
                If iNorm > 0 Then
                    iNorm = iNorm - 1
                Else
                    iNorm = iNorm + 1
                End If
            End If
            If Mid(sRaw, J, 1) = Chr(147) Then
                iSmart = iSmart + 1
            End If
            If Mid(sRaw, J, 1) = Chr(148) Then
                iSmart = iSmart - 1
            End If
        Next J
        If iNorm > 0 Or iSmart > 0 Then
            Selection.Range.HighlightColorIndex = wdYellow
        End If
        Selection.Collapse Direction:=wdCollapseEnd
        Selection.Find.Execute
    Wend
    Selection.HomeKey Unit:=wdStory
    Application.ScreenUpdating = True
End Sub

When the macro is done, what you end up with is a bunch of text selections highlighted if they need to be visually checked. The macro won't, however, finding ending quotes that are outside the paragraph in which the first quote occurs.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13293) applies to Microsoft Word 2007, 2010, and 2013.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Making Ignore All Work for a Document on All Systems

When you tell Word's spell checker to ignore all instances of a misspelling, you may expect that the misspelling will be ...

Discover More

Closing Documents after a Hyperlink

When you click a hyperlink that takes you to another document, Word dutifully opens the new document in its own window. What ...

Discover More

Booklet Printing in Word

Need to create a booklet with Word? Depending on your version, it could be as easy as changing how you print your final ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Correctly Repeated Words

There are times when you need to repeat a word in a document, but doing so triggers an "error reaction" from Word's spelling ...

Discover More

Allowing Passive Voice in Writing

When you have Word do grammar checking on your document, it typically marks everything it considers wrong with the way you ...

Discover More

Accepting Capitalization of a Proper Noun

If a word is normally supposed to be lowercase, Word helpfully lets you know if you incorrectly capitalize it. If you really ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 6 - 0?

2016-12-07 04:11:07

Ken Endacott

The macro has some shortcomings, for example it won’t detect a singleton closing quote, nor will it detect incorrectly nested quotes that are a mixture of straight and curly quotes.
The following macro will correctly match straight with straight and curly with curly quotes even if they are nested or overlap. It does this by building a list of all quotes in the paragraph and then deleting matched quotes, inner nested first. If there are anything left in the list then there are mismatched quotes. The macro removes any existing highlighting in the document before checking. It is reasonably fast, taking around 15 seconds to process a 500 page document.

Sub MarkUnevenQuotesWithNesting()
Dim Q
Dim ch As Long
Dim sRaw As String
Dim changeTest As Boolean
Dim J As Long
Dim i As Long

ActiveDocument.Range.HighlightColorIndex = wdNoHighlight
i = 0
Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = False
Selection.Find.ClearFormatting
With Selection.Find
.Text = """"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
End With
Selection.Find.Execute

While Selection.Find.Found
Set Q = Nothing
Set Q = New Collection
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
sRaw = Selection.Text
For J = 1 To Len(sRaw)
ch = Asc(Mid(sRaw, J, 1))
If ch = 34 Or ch = 147 Or ch = 148 Then
Q.Add ch
End If
Next J

If Q.Count Mod 2 = 0 Then
Do
changeTest = False
J = 2
Do While J <= Q.Count
If (Q(J - 1) = 34 And Q(J) = 34) Or _
(Q(J - 1) = 147 And Q(J) = 148) Then
Q.Remove J
Q.Remove J - 1
changeTest = True
J = 2
Else
J = J + 1
End If
Loop
Loop While changeTest
End If

If Q.Count > 0 Then
Selection.Range.HighlightColorIndex = wdYellow
i = i + 1
End If
Selection.Collapse Direction:=wdCollapseEnd
Selection.Find.Execute
Wend
Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = True
MsgBox i & " paragraphs contain mismatched quotes"
End Sub


2016-12-05 10:23:30

Rose

I just wanted to thank you SO MUCH for this macro. A computer-savvy friend helped me install it, and it works like a charm.

As an editor, I can vouch for the fact that missing quotation marks is one of the easiest things to miss when correcting a document. I absolutely love this software, and it is the first thing I run on a document.

Thanks again.


2016-11-03 20:21:19

Rose Lipscomb

As an editor for fiction books, I find this one of the easiest things to miss and also wish for software that would provide, at least, a basic check. I did not know what you meant by smart quotes and non-smart quotes. Can you provide a link to a reference on this?


2016-06-10 10:18:15

Tom Holzel

I am a writer, not a computer nerd, so the suggestion I insert a macro somewhere is way beyond my competence.

Is there not a program or app I could run?


2016-04-23 21:20:43

Richard

"Pages" in Apple has it. It even will show things like my keyboard flipping over to French and changing the mark in don't to an accent. It will even show if you not only left it off the front or back end it will pick up you missing fully hitting the shift key and just leaving a (') I totally have transferred all my manuscript over just to check on this.


2014-11-01 05:20:23

David

Thank you for this information and explanation. I'll set up a macro and run it for each chapter.
Sincerely,
David


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.