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
DTE.ActiveDocument.Activate()
Dim selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection
Dim txt As String = selection.Text
selection.Cut()
selection.Text = lftParen + txt + rtParen
selection.CharLeft()
End Sub