Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 05-27-2021, 08:36 PM
Guessed's Avatar
Guessed Guessed is offline Enclose All Instances of a Specific Custom Style in Brackets Windows 10 Enclose All Instances of a Specific Custom Style in Brackets Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
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
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enclose All Instances of a Specific Custom Style in Brackets find and delet all text within brackets and the brackets themselves wrdy Word 2 08-03-2017 06:55 PM
Enclose All Instances of a Specific Custom Style in Brackets Word forces use of a specific style C_Hawk1996 Word 1 04-13-2016 05:35 AM
Enclose All Instances of a Specific Custom Style in Brackets How to set the left indent in a specific style. OfficeBoy95 Word 2 05-12-2014 06:31 PM
How do I add a custom style to tab button? kennethc Word 1 04-11-2014 05:25 PM
How to set style automatically for specific texts ragesz Word 2 07-25-2013 07:08 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:44 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft