Results 1 to 13 of 13
  1. #1
    New Lounger
    Join Date
    Apr 2001
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Quote/Paren Macro

    Is there a MSWord97 macro that places quotes and or parentheses around selected text?

  2. #2
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: Quote/Paren Macro

    No, there isn't. One could be written, though.
    Charles Kyle Kenyon
    Madison, Wisconsin

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Quote/Paren Macro

    Two for the price of one <g>:

    Sub ParensAroundSelection()
    Dim rngSel As Range
    Set rngSel = Selection.Range
    rngSel.Text = "(" & Trim(rngSel) & ")"
    End Sub

    Sub QuotesAroundSelection()
    Dim rngSel As Range
    Set rngSel = Selection.Range
    rngSel.Text = Chr(147) & Trim(rngSel) & Chr(148)
    End Sub

  4. #4
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Quote/Paren Macro

    Gary,

    This wipes out formatting in the text.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Quote/Paren Macro

    Hi Geoff,

    Good point.
    Interestingly, if you select an individual word that has say bold or italic applied, then the formatting is preserved - the only drawback is that the quotes or parens take on the bold or italic formatting.
    But if you select a run of text which contains a bold or italic word somewhere in the middle, then that bold or italic formatting is lost.

    Anyway these get around that problem; the only thing lost this way is that handy trim space feature (which could of course get worked back in if one wanted to take the time):

    Sub ParensAroundSelection2()
    Dim rngSel As Range
    Set rngSel = Selection.Range
    rngSel.InsertBefore "("
    rngSel.InsertAfter ")"
    End Sub

    Sub QuotesAroundSelection2()
    Dim rngSel As Range
    Set rngSel = Selection.Range
    rngSel.InsertBefore Chr(147)
    rngSel.InsertAfter Chr(148)
    End Sub

    Gary

  6. #6
    New Lounger
    Join Date
    Apr 2001
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Quote/Paren Macro

    <P ID="del"><FONT SIZE=-1>Post deleted by MDGersh</FONT>

  7. #7
    New Lounger
    Join Date
    Apr 2001
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Quote/Paren Macro

    Thanks Gary and Geoff for forging a solution, testing it, finding it wanting and making repairs--all before I could check back in. This is what makes the net a wonder. You get my vote for MVP's

  8. #8
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Quote/Paren Macro

    A colleague wrote this a long time ago and this does take care of trimming any spaces.

    Hope it helps

    ADD BRACKETS

    Public Sub AddBrackets()
    AddDel "(", ")"
    End Sub

    Private Sub AddDel(B$, a$)
    Dim strSel$
    strSel$ = WordBasic.[Selection$]()
    If WordBasic.[Right$](strSel$, 1) = " " Then
    strSel$ = WordBasic.[Left$](strSel$, Len(strSel$) - 1)
    End If
    strSel$ = B$ + strSel$ + a$
    WordBasic.Insert strSel$
    End Sub



    ADD QUOTES

    Public Sub AddQuotes()
    AddDel Chr(34), Chr(34)
    End Sub

    Private Sub AddDel(B$, a$)
    Dim strSel$
    strSel$ = WordBasic.[Selection$]()
    If WordBasic.[Right$](strSel$, 1) = " " Then
    strSel$ = WordBasic.[Left$](strSel$, Len(strSel$) - 1)
    End If
    strSel$ = B$ + strSel$ + a$
    WordBasic.Insert strSel$
    End Sub

  9. #9
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Quote/Paren Macro

    I think you would probably find this would suffer the same fate as Gary's original suggestion- ie, formatting cleared out.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  10. #10
    Star Lounger
    Join Date
    Jan 2001
    Location
    Iowa, USA
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Quote/Paren Macro

    Taking a stab here... seems like the easiest way to do this would be to record keystrokes that cut the selection, type the pair of parens (or quotes or braces or whatever), arrow left once then paste.

    That should preserve formatting and suchlike.

    Sue

  11. #11
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Quote/Paren Macro

    Interesting & nice thought. However, if you have smart cut n' paste set under Tools/Options/Edit or if you select a couple words by double clicking, you will include the trailing space. Then when you cut in the middle of a sentence, you leave only one space between words. Typing () leaves the last parenthesis up against the next word.

    I suppose you could arrow right in the macro & then type a space, unless you were at the end of a sentence. Seems like a practical solution.

  12. #12
    Star Lounger
    Join Date
    Jan 2001
    Location
    Iowa, USA
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Quote/Paren Macro

    Good point...

    I was thinking that you would manually select what you wanted in parens...since there's no way for the macro to know whether you want a single word or several...and would leave out the space. The macro would just cut, type (), move left one and paste.

    That way it wouldn't matter if there was a space or if it was the end of the sentence.

  13. #13
    Lounger
    Join Date
    May 2001
    Location
    Arlington Heights IL
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Quote/Paren Macro

    One could always turn Smart Cut/Paste off at the beginning and turn it back on at the end of the macro. Somewhat brutish, but it works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •