I created this before the code snippit region came along. This macro will work with VS2003 and VS2005. Simply highlight the code you want and a dialog box will come up asking for the name. Note depending on the location the #region and #endregion will be at those positions.
Sub RegionIt()
Dim sWhat As String
Â
sWhat = InputBox("Region Name")
Â
If (sWhat <> "") Then
Dim selection As TextSelection = DTE.ActiveDocument.Selection()
Dim start As EditPoint = selection.TopPoint.CreateEditPoint()
Dim endpt As EditPoint = selection.BottomPoint.CreateEditPoint()
DTE.UndoContext.Open("Comment Region")
Try
start.Insert("#region " & sWhat & Chr(13))
endpt.Insert(Chr(13) & "#endregion")
Â
Finally
'If an error occured, then need to make sure that the undo
'context is cleaned up. Otherwise, the editor can be left
'in a perpetual undo context
DTE.UndoContext.Close()
End Try
End If
End Sub