Using VS Macros To Speed Up Text Entry

Often times my position requires me to enter fairly large sets of copy into the websites I am developing. These pieces can be anything from press releases to taglines and product information. Regardless of their content, I am always left doing one thing over and over: adding HTML tags. After hours of repeating this task, my hands get cranky – very cranky. Naturally I went looking for a programmatic solution, and found one in using Visual Studio Macros!

For now, here is a quick snapshot to get you started. The below code allows me to quickly add paragraph tags to the current selection in a VS2010 editor/window. To develop a Macro, simply go into the Tools -> Macros -> Macro IDE and open up the code file.

Public Sub WrapInParagraph()
    DTE.ActiveDocument.Selection.Text = "

" + DTE.ActiveDocument.Selection.Text + "

"
End Sub

After building the project, hop back into VS2010 and select Options under the Tools menu. You can now search for your command in the Environment -> Keyboard panel and assign it a shortcut.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>