Another complicated Find/Replace via code

  • Thread starter Southern at Heart
  • Start date
S

Southern at Heart

That last find/replace had a lot easier answer than I thought it would!
Hopefully this one does, too.
I need to find the bracket sign }
....and if it is followed by a paragraph mark then do nothing. If it is not
followed by a paragraph mark, then add a paragraph mark after it.
(There will be multiple instances of the bracket sign and I need to do this
to all of them)
thanks,
Southern at Heart
 
D

Doug Robbins - Word MVP

Use the following in a Wildcard Edit Replace.

For Find what, use

\}[!^13]{1}

for Replace with, use

}^p


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

StevenM

Sub TestAPM()
Dim oRange As Range
Dim nPos As Long

Set oRange = ActiveDocument.Range
nPos = 1
While (nPos > 0)
nPos = InStr(oRange.Text, "}")
If nPos > 0 Then
oRange.Start = oRange.Start + nPos
oRange.End = oRange.Start + 1
If oRange.Text <> vbCr Then
oRange.InsertParagraphBefore
End If
oRange.Collapse wdCollapseEnd
oRange.End = ActiveDocument.Range.End
End If
Wend
End Sub

Steven Craig Miller
 
T

Tony Jollans

That needs a tweak to stop it removing the character after the brace

Find \}([!^13]{1}) Replace }^p\1


--
Enjoy,
Tony

Doug Robbins - Word MVP said:
Use the following in a Wildcard Edit Replace.

For Find what, use

\}[!^13]{1}

for Replace with, use

}^p


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Southern at Heart said:
That last find/replace had a lot easier answer than I thought it would!
Hopefully this one does, too.
I need to find the bracket sign }
...and if it is followed by a paragraph mark then do nothing. If it is
not
followed by a paragraph mark, then add a paragraph mark after it.
(There will be multiple instances of the bracket sign and I need to do
this
to all of them)
thanks,
Southern at Heart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top