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
.
- 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
- 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