Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Aug 2015
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro for Unmatched Quote Marks

    There was a thread http://windowssecrets.com/forums/sho...uotation-marks that is now closed that I'd like some help with.

    Macropod posted this: You could add logic to allow the user to continue where the quote is known to span multiple paragraphs. By one convention, each such paragraph begins with an opening quote, but only the final one has a closing quote.

    Is there someone who could create a command to deal with this situation? A line that basically says, "This one's OK, skip it and move to the next"? I am an editor and use the macro all the time. Currently I have to add quote marks in the middle of a multi-paragraph quotation so the macro will move on and add a comment to myself to remember to delete the quote mark when I've finished editing.

    Thanks!

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Try:
    Code:
    Sub TestQuotes()
    Dim i As Long, Rng As Range
    With ActiveDocument
    For i = 1 To .Paragraphs.Count
      With .Paragraphs(i).Range
        If (Len(.Text) - Len(Replace(.Text, Chr(34), vbNullString))) Mod 2 <> 0 Then
          Set Rng = .Duplicate
          With Rng
            .MoveEndUntil Chr(34), wdForward
            .MoveEndUntil vbCr, wdForward
            If InStrRev(.Text, Chr(34)) <> Len(.Text) Then
              .Select
              MsgBox "Selected range has unmatched plain quotes", vbExclamation
              Exit Sub
            End If
          End With
          i = i + Rng.Paragraphs.Count - 1
        End If
        If Len(Replace(.Text, Chr(147), vbNullString)) <> Len(Replace(.Text, Chr(148), vbNullString)) Then
          Set Rng = .Duplicate
          With Rng
            .MoveEndUntil Chr(148), wdForward
            .MoveEndUntil vbCr, wdForward
            .Start = .Start + 1
            If (InStrRev(.Text, Chr(148)) <> Len(.Text)) Or (InStr(.Text, Chr(147)) <> 0) Then
              .Select
              MsgBox "Selected range has unmatched smart quotes", vbExclamation
              Exit Sub
            End If
          End With
          i = i + Rng.Paragraphs.Count - 1
        End If
      End With
    Next
    End With
    End Sub
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    New Lounger
    Join Date
    Aug 2015
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, Paul.

    Unfortunately that macro did not work. I ran it on a test document and it highlighted the entire document and told me there were unmatched quotes in the "selection."

    Any other ideas would be appreciated.

    Julie

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    It works in my testing. Perhaps you could give more detail about how it's not working for you, particularly the kind of content you're working with.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    New Lounger
    Join Date
    Aug 2015
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Paul,

    You're correct, it does work, sort of. Now, when there are unmatched quote marks the tool identifies both the paragraph that has the mismatched quote marks as well as the preceding and following paragraphs. Not exactly what I'm looking for. What I'd really like is a way to tell the macro "This mismatch is OK, please find the next mismatch." I am working in Word documents only.

    Also, is there a way to go the the next instance without going back up to the ribbon and hitting the macro button and telling it to run again? (Can you tell I'm not in IT?)

    I appreciate your time on this!

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    When an unmatched set of quotes is found, the macro selects the range starting from the opening quote till the end of the unmatched range, not any preceding paragraphs. If you fix an unmatched set then re-run the macro, it shouldn't exit before the next mismatch.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •