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




.



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 ...
    (microsoft.public.excel.programming)
  • Re: Multiple Active Worksheets
    ... When trying to use a selection of more ... Sub arrayLoop() ... 'Dim objChart As ChartObject ...
    (microsoft.public.excel.programming)
  • Re: Cant Undo Macro Command
    ... John's code worked on the Selection. ... Dim myRngToCopy As Range ... Dim cell As Range ... ' Specify the Undo Sub ...
    (microsoft.public.excel.programming)
  • 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 ...
    (microsoft.public.access.forms)
  • 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 ...
    (microsoft.public.excel.misc)