2
votes

I have a numbered list in Word and, after each entry, there is a paragraph mark. In the end, after the paragraph mark, there's a quote mark . I want to remove the last paragraph mark from the numbered list, in order to put the quote mark next to the last line of the numbered list. However, using Find and Replace for "^p" & ChrW(8220) removes the paragraph but also removes the numbering for the last entry.

I have managed to do a workaround by selecting the quote mark, moving left one character and then deleting one character. However, it's inconsistent and I don't trust it to be reliable.

  Selection.Find.ClearFormatting
    With Selection.Find
        .Text = ChrW(8220)
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.TypeBackspace

enter image description here

Is there another way to to put the quotation next to the last entry without breaking the numbering?

2
Find the "^p and delete it. Move left one character and insert a ". - freeflow

2 Answers

1
votes

There are various ways this could be done; it's mostly a matter of personal preference, which approach is used. Here are two. One uses a Wildcard Find with Replacement; the other manipulates the Range objects. The first probably executes faster (although that wouldn't be noticeable in this context) and leaves only one "footprint" in Word's Undo list.

Note: I prefer working with a Range rather than Selection. The first option could be done with Selection; the second is better with a Range.

  1. Does a wildcard search on a paragraph mark plus the quote. Notice that each term is within parentheses: These make it possible to work with the term in the Replacement - the parentheses define expressions.

This makes it possible to reverse the information as the Replacement: the quote comes before the paragraph mark - the paragraph mark remains intact (the bullets are not lost).

Sub TestFindParaAndQuote()
    Dim rngFind As Word.Range

    Set rngFind = ActiveDocument.content
    rngFind.Find.ClearFormatting
    With rngFind.Find
        .Text = "(^13)(" & ChrW(8220) & ")"
        .Replacement.Text = "\2\1"
        .Forward = True
        .wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceOne
    End With

End Sub
  1. When a Find.Execute is successful, the Range (or Selection) moves to the found term. Here, if bFound = True then: 1) the quote is inserted before the Range; 2) the Range is collapsed to its end-point (after the original quote); 3) then extended backwards to include that quote; 4) and the entire Range deleted. (The following line, which is commented out, can be included if the paragraph following the original quote should also be deleted.)

This example is useful for understanding how to work with Find when standard Find/Replace can't do the job for some reason.

Sub TestFindParaAndQuote()
    Dim rngFind As Word.Range
    Dim bFound As Boolean

    Set rngFind = ActiveDocument.content
    rngFind.Find.ClearFormatting
    With rngFind.Find
        .Text = "^p" & ChrW(8220)
        .Forward = True
        .wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        bFound = .Execute
        If bFound Then
            rngFind.InsertBefore ChrW(8220)
            rngFind.Collapse wdCollapseEnd
            rngFind.MoveStart wdCharacter, -1
            'rngFind.MoveEnd wdCharacter, 1 'use this, too, if the paragraph mark should be removed
            'rngFind.Select                 'for testing purposes
            rngFind.Delete
        End If
    End With

End Sub
0
votes

If you remove the paragraph mark before the closing quotation marks the last paragraph of the list will inherit the formatting of the paragraph that follows it.

If the list has been formatted using a numbered style you can apply that style to the paragraph containing the quotes before deleting the paragraph mark before it.

If not it will be more difficult for you. You could try adding the quote marks to the last paragraph of the list then deleting the final paragraph, but that may not work if it is the final paragraph in the document.