Written by Allen Wyatt (last updated May 25, 2020)
This tip applies to Word 2007, 2010, 2013, 2016, and Word in Microsoft 365
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, find ending quotes that are outside the paragraph in which the first quote occurs.
Note:
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, 2013, 2016, and Word in Microsoft 365.
Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!
If a word is normally supposed to be lowercase, Word helpfully lets you know if you incorrectly capitalize it. If you ...
Discover MoreOne of the mostly helpful tools that Word includes is a grammar checker. Sometimes, however, the grammar checker might ...
Discover MoreWhen you have Word do grammar checking on your document, it typically marks everything it considers wrong with the way ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-10-25 17:06:59
Rob
That is so helpful. Works brilliantly!
Thank you !!!
2021-08-04 16:32:49
Joy Freeman
I made this work (after some trial and error) on my Mac by replacing "147" with "210" and "148" with "211" in the macro. I'm a rudimentary user of macros so if there is something else I should also change, please let me know.
2021-02-25 08:44:44
Nelli
Hello! In my texts we are using a double low-9 quotation mark as an opening quotation mark. Thus all instances of quotations marks are marked in yellow or have a comment (when using another macro suggested below), as macros don't recognize low-9 as the opening quotation mark.
I tried substituting Chr(34) with Chr(132), if I got that right, but it didn't help.
https://everythingfonts.com/ascii/codes/132
As an example:
„Jilly-bean?“
The opening quotation mark is not recognized by macros :(
Any help would be really appreciated!
2020-08-06 11:52:46
Pablo Morales
Here's my stab at this, a bit more simple, but it seems to work. Stray quotes are marked with a comment.
Sub FindStrayQuotes()
Application.ScreenUpdating = False
ActiveDocument.Content.HighlightColorIndex = wdNoHighlight
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.Highlight = True
.Text = "^0147[!^0147^0148]@^0148"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchWildcards = True
.MatchCase = False
.MatchWholeWord = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
With ActiveDocument.Content
With .Find
.Highlight = False
.Text = "[^0147^0148]"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchWildcards = True
.MatchCase = False
.MatchWholeWord = False
.Execute
End With
Do While .Find.Found
.Comments.Add .Duplicate, "Pair missing?"
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
ActiveDocument.Content.HighlightColorIndex = wdNoHighlight
Application.ScreenUpdating = True
End Sub
2019-12-21 05:13:12
tomofnz
By the way, to use this macro, copy the script. In Word, go to View tab > Macros rolldown. Choose View Macros.
Enter a Name in the Macro Name field. In the dialog buttons, choose Create.
A Visual Basic editor will open on top of Word. Here, paste the copied script over the template starter text and press Save (in the visual basic editor). Close Visual Basic. Go to Macros panel again and select your saved macro and press Run (there's also a Run command in the visual basic editor)
2019-12-21 05:05:11
tomofnz
Thanks Allen. This macro script works well.
If anyone is interested:
Before you run the macro, select all document text, then make sure in Home tab that highlighting of text is cleared (or No Color).
After you run the macro, go to Find > Advanced, Format > Highlight (with no text in textfield) and hit Next to jump through the results, if any.
2019-07-22 17:09:36
Allen
Jackie,
Take a look at the yellow box at the very end of the tip. It includes a link that leads to helpful info in this regard.
-Allen
2019-07-22 16:22:38
Jackie Oliveira
Several times over the years of receiving your newsletter I have tried to recreate your macros but with no success. Once I believe you told me all I had to do was copy it into a "create macro" and that also has failed. How do I use the macros you provide?
Thank you for your assistance
2019-07-20 14:25:31
Robert blanton
If you modify the macro to use paragraph marks instead of quote marks for the start of the selection, you can test for unbalanced quotes. Just change your <0 to <> 0
Had to change your .find setting to allow for paragraph marks to be found.
Also, the smart quotes in my document are 210 and 211, not sure if it's the character set or ??
I put a limit on the main loop when I changed to paragraphs, it didn't seem to end. I haven't debugged that yet.
2019-07-15 03:39:16
Jürgen Beschorner
The macro is really great, but I can't get it working when I'm looking for mismatching double angle quotes (»...«), Chr (187) resp. Chr (171). Could you, please, give me a hint how to solve this? Your help is much appreciated!
2018-01-22 02:25:03
Ashok
Hi Ken Endacott,
Your macro is working great for double quotes and it is very useful for me. However, it is not working for single Quotes. It would be grateful if you provide the macro for single quotes as well.
Thanks & Regards,
Ashok
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
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments