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
Selection.Words(1).Select
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
myRange.Select

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")

Regards,
Klaus


"Graham Mayor" <gmayor@xxxxxxxxxxxxxxxxxx> schrieb im Newsbeitrag
news:uR4lDN3nHHA.4192@xxxxxxxxxxxxxxxxxxxxxxx
How about

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


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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Angie M. wrote:
Hello,

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




.