Re: Define paragraph range

Or a more elaborate version:

Sub AddBrackets()
Dim myRange As Range
Dim myFont As Font

' If nothing is selected, select current word
If Selection.Type = wdSelectionIP Then
End If
Set myRange = Selection.Range.Duplicate

' remove trailing space if necessary
myRange.MoveEndWhile Cset:=" ", Count:=wdBackward

' braces should get all the font properties of the first character
Set myFont = myRange.Characters(1).Font.Duplicate

myRange.InsertBefore "("
myRange.InsertAfter ")"
myRange.Characters.First.Font = myFont
myRange.Characters.Last.Font = myFont

End Sub

-- select current word if nothing is selected,
-- does not loose any formatting in the selected text,
-- make sure the opening brace has the formatting of the first character,
-- make sure the closing brace has the same formatting as the opening brace,
-- remove trailing spaces (from Word's "smart word selection")


"Graham Mayor" <gmayor@xxxxxxxxxxxxxxxxxx> schrieb im Newsbeitrag
How about

Sub AddBrackets()
Dim sText As String
sText = Selection
Selection.TypeText "(" & sText & ")"
End Sub

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site
Word MVP web site
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Angie M. wrote:

I need to create a macro that inserts a bracket at the start and end
of a portion of text. The user will select the text (it can be a few
characters or an entire page). Any help would be appreciated. I'm
on Word 03.

Thank you


Relevant Pages

  • Re: Cant Undo Macro Command
    ... Mr. Peterson: As always, that was very helpful. ... John's code worked on the Selection. ... Dim myRngToCopy As Range ... ' Specify the Undo Sub ...
  • Re: Multiple Active Worksheets
    ... When trying to use a selection of more ... Sub arrayLoop() ... 'Dim objChart As ChartObject ...
  • Re: Cant Undo Macro Command
    ... John's code worked on the Selection. ... Dim myRngToCopy As Range ... Dim cell As Range ... ' Specify the Undo Sub ...
  • Re: Reusable Form & Code
    ... Looks like I win the Dumb Question award. ... Public Sub cmdOkFindFirm_Click ... 'Find record for main form based on selection in dialog form. ... Dim rst As DAO.Recordset ...
  • Re: Tranfering data from the column to text file .
    ... End Sub ... This means that only the selection will be saved ... > Dim WholeLine As String ... > Dim FNum As Integer ...