View Single Post
Old 07-24-2019, 11:32 AM   #1
Leonatus
Wizard
Leonatus ought to be getting tired of karma fortunes by now.Leonatus ought to be getting tired of karma fortunes by now.Leonatus ought to be getting tired of karma fortunes by now.Leonatus ought to be getting tired of karma fortunes by now.Leonatus ought to be getting tired of karma fortunes by now.Leonatus ought to be getting tired of karma fortunes by now.Leonatus ought to be getting tired of karma fortunes by now.Leonatus ought to be getting tired of karma fortunes by now.Leonatus ought to be getting tired of karma fortunes by now.Leonatus ought to be getting tired of karma fortunes by now.Leonatus ought to be getting tired of karma fortunes by now.
 
Leonatus's Avatar
 
Posts: 1,060
Karma: 11391181
Join Date: Mar 2013
Location: Guben, Brandenburg, Germany
Device: Kobo Clara 2E, Tolino Shine 3
Word macro to check missing quotation marks

Usually, I apply Toxaris' "Check Dialogue" tool to check for missing Quotation marks. That is really great - when it works. Unfortunately, on one of my Computers it doesn't work at all for doubtful reasons. So, I thought by myself, it would be good to have a Word macro that could do this.

In the Internet, I found one that highlights all paragraphs with mismatching Quotation marks. It is this one:
Code:
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
Unfortunately, it works, as I understood, for so called curly quotes. I'm working preferably with double angle quotation marks (»...«), Chr (187) resp. Chr (171). Whatever I tried, but I didn't get the macro working for this.
As I'm no technician, it would be of no sense to study programming VBA only for this purpose. Is there Perhaps someone who could provide us with a suiting macro of this sort? That would be very helpful.
Leonatus is offline   Reply With Quote