Thread: [Solved] Needed macro, please
View Single Post
 
Old 07-16-2024, 09:36 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

Thanks Andrew,


Tweaking your code a bit, I think we can prevent unwanted growth of the dbl brackets if the code is repeated.


Code:
Sub Macro1()
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  oRng.InsertBefore "*"
  With oRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "([!\[\(])([\[\(])([!\[\(]*)([\]\)])([!\]\)])"
    .Replacement.Text = "\1[[\3]]\5"
    .MatchWildcards = True
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchKashida = False
    .MatchDiacritics = False
    .MatchAlefHamza = False
    .MatchControl = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .Execute Replace:=wdReplaceAll
  End With
  ActiveDocument.Characters(1).Delete
  MsgBox Asc(ActiveDocument.Characters.Last.Previous)
  If ActiveDocument.Characters.Last.Previous = Chr(13) Then
    ActiveDocument.Characters.Last.Previous.Delete
  End If
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote