Re: VS Macro to wrap selection in parens, curly braces etc

This is a simple VS macro to wrap the selected text in  one of (){}[]<>.    I am just learning how to write macros and use the DTE.  Any comments or suggestions for improvements will be appreciated.

   ' wraps selected text with matching (){}[]<>
   ' when the macro runs it promts the user for   one of  ({[<    and wraps
   ' the selected text with a matched pair and finally positions the
   ' cursor just before the closing paren.  Any other key
   ' cancels the operation
     Public Sub Parens()

      Dim rtParen As String
      Dim lftParen As String = InputBox("Enter one of: ( { [", "Wrap Selected Text in Parens", "(")

      Select Case lftParen
         Case "("
            rtParen = ")"

         Case "{"
            rtParen = "}"

         Case "["
            rtParen = "]"

         Case "<"
            rtParen = ">"

         Case Else
            Return  'abort

      End Select

      Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection
      Dim txt As String = selection.Text

      selection.Text = lftParen + txt + rtParen

   End Sub


Re: VS Macro to wrap selection in parens, curly braces etc

Thanks maddog. I've never been much of a macro whiz myself, but I'm sure very nice things can be done. Integrating ViEmu better with VS macros is something I intend to do at some point, as the possibilities are great.


  - Jon