View Single Post
 
Old 03-25-2023, 01:56 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
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

This macro works for me. You can assign a keyboard shortcut to run it by setting that shortcut as Alt+)
Code:
Sub CloseBracketsAndFormat()
  Dim aRng As Range
  Selection.TypeText ")"
  Set aRng = Selection.Range
  aRng.MoveStartUntil "(", -100
  If Len(aRng.Text) > 2 Then
    aRng.Style = "styMyStyl"
  End If
End Sub
Note that I've chosen to limit the distance backwards that the macro searches for the starting bracket to 100 characters. You can fiddle this number if you want to search more or less characters.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote