Make a Hotkey Macro for Comments in .NET

I like having comments in the code that shows who did it and when. You can obviously get more complex, but this is good for me.

To make your own macro to look like “//SBE 06/04/2004: “, do this:

  1. Open Macro Explorer w/in VS.NET. (Tools –> Macros –> Macro Explorer)
  2. Create a function like the one below in any module. My example below uses a module called “Module1” (those are my initials BTW).
  3. Sub Comment()
    DTE.ActiveDocument.Selection.Text = "//SBE " +
    Date.Today.ToString("MM/dd/yyyy") + ": "
    End Sub
  4. Close Macro Explorer and go to Tools –> Options –> Environment –> Keyboard.
  5. Select your macro, like (Macros.MyMacros.Module1.Comment)
  6. Select “Global” or whatever you like, in “Use new shortcut in”
  7. Go To “Press shortcut key(s)” and select on your keyboard a combination. Mine is -Q. Hit “Assign”. If it is already in use, it will tell you to create your own mapping scheme. Just do it.
  8. Test it out in your code.

Update 5/19/05: For Visual Studio 2005, you will find the dialog at Tools –> Customize –> Keyboard…


One response to “Make a Hotkey Macro for Comments in .NET”

Leave a Reply

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