Thread: [Solved] Needed macro, please
View Single Post
 
Old 07-15-2024, 04:28 AM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

This could likely be refined, but I don't have time right now:


Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = "[\[\(]*[\]\)]"
    .MatchWildcards = True
    .Wrap = wdFindStop
    While .Execute
      oRng.Characters.First.InsertBefore Chr(Asc(oRng.Characters.First))
      oRng.Characters.Last.InsertAfter Chr(Asc(oRng.Characters.Last))
      oRng.Collapse wdCollapseEnd
    Wend
  End With
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = "(("
    .Replacement.Text = "[["
    .Execute Replace:=wdReplaceAll
  End With
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = "))"
    .Replacement.Text = "]]"
    .Execute Replace:=wdReplaceAll
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote