View Single Post
 
Old 05-27-2021, 06:11 AM
Matt C's Avatar
Matt C Matt C is offline Windows 10 Office 97-2003
Advanced Beginner
 
Join Date: May 2021
Location: London, UK
Posts: 30
Matt C is on a distinguished road
Question Enclose All Instances of a Specific Custom Style in Brackets

Hi folks

I've been tinkering with the VBA code below which encloses curly brackets (parentheses) around selected text but am looking for a way to apply this method automatically to every paragraph in a document which is formatted with a specific custom style (let's call it "Custom Style").

Secondly, I then want to do the reverse (which can be a separate macro), i.e. remove left and right curly brackets from the beginning and end of "Custom Style" paragraphs).


Quote:
Dim iCount As Integer

iCount = 1

While Right(Selection.Text, 1) = " " Or _
Right(Selection.Text, 1) = Chr(13)
Selection.MoveLeft Unit:=wdCharacter, Count:=1, _
Extend:=wdExtend
iCount = iCount + 1

Wend

Selection.InsertAfter ")"
Selection.InsertBefore "("
Selection.MoveRight Unit:=wdCharacter, Count:=iCount
All help appreciated in advance. Many thanks.
Reply With Quote