Sub MatchDoubleQuotes()
' Paul Beverley - Version 21.02.24
' Check whether double quotes match up

Set rng = ActiveDocument.Content
With rng.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = "''"
  .Wrap = wdFindContinue
  .Forward = True
  .Replacement.Text = ""
  .MatchWildcards = False
  .Execute
  DoEvents

If .Found = True Then
Beep
  rng.Select
  MsgBox "Warning: this is two single quotes!"
  Exit Sub
End If

  .Text = "`"
  .Execute
  DoEvents
End With

If rng.Find.Found = True Then
Beep
  rng.Select
  MsgBox "Warning: backticks detected!"
  Exit Sub
End If

For Each myPara In ActiveDocument.Paragraphs
  myText = myPara.Range.Text
  l = Len(myText)
  L1 = Len(Replace(myText, Chr(34), ""))
  Lopen = Len(Replace(myText, ChrW(8220), ""))
  Lclose = Len(Replace(myText, ChrW(8221), ""))
  
  If (l - L1) Mod 2 <> 0 Or Lopen <> Lclose Then
    myPara.Range.Font.Underline = True
    myCount = myCount + 1
    StatusBar = "Found: " & myCount
    DoEvents ' Debug.Print "Found: " & myCount
  End If
Next
StatusBar = ""
If myCount = 0 Then
  MsgBox ("All clear!")
Else
  MsgBox ("Number of suspect paragraphs: " & Trim(myCount))
End If

Set rng = ActiveDocument.Content
With rng.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = ""
  .Font.Underline = True
  .Wrap = wdFindStop
  .Forward = True
  .MatchWildcards = False
  .Execute
  DoEvents
End With
Do While rng.Find.Found = True
  If rng.Font.Color <> 9999999 Then
    rng.HighlightColorIndex = wdYellow
  End If
  rng.Collapse wdCollapseEnd
  rng.Find.Execute
  DoEvents
Loop

Selection.HomeKey Unit:=wdStory
With Selection.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = ""
  .Font.Underline = True
  .Replacement.Text = ""
  .MatchWildcards = False
  .MatchWholeWord = False
  .MatchSoundsLike = False
  .Execute
End With

End Sub