View Single Post
 
Old 05-27-2021, 08:36 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Stage one macro might work along these lines
Code:
Sub DamnBrackets()
  Dim aPar As Paragraph, aRng As Range
  For Each aPar In ActiveDocument.Paragraphs
    If aPar.Style = "Normal" Then
      Set aRng = aPar.Range
      Do While Left(aRng.Text, 1) = " "
        aRng.MoveStart Unit:=wdCharacter, Count:=1
      Loop
      Do While Right(aRng.Text, 1) = vbCr Or Right(aRng.Text, 1) = " "
        aRng.MoveEnd Unit:=wdCharacter, Count:=-1
      Loop
      If Len(aRng.Text) > 0 Then
        aRng.InsertAfter ")"
        aRng.InsertBefore "("
      End If
    End If
  Next aPar
End Sub
To reverse it the simplest thing to do would be to find and replace those characters with nothing. If you need to identify which ones were inserted by the first macro then it becomes a lot harder unless you tagged them in some way as you insert them. Can you use brackets that don't appear elsewhere in the text?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote