VS Macro to Insert GUIDs

Published 03 January 07 03:56 AM | admin 

One of the most useful macros I ever wrote in VS was but a single line.  All it does is insert a GUID at the current selection point.  It was so useful I wrote it twice; once to insert lowercase and once to insert uppercase GUIDs.  Here it is:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics

Public Module MainModule

    Sub InsertLowerCaseGuid()
        DTE.ActiveDocument.Selection.Text = Guid.NewGuid.ToString("D").ToLower()
    End Sub

    Sub InsertUpperCaseGuid()
        DTE.ActiveDocument.Selection.Text = Guid.NewGuid.ToString("D").ToUpper()
    End Sub

End Module

Of course, the observation that I'm trying to make by mentioning this at all is that sometimes we forget that we're sitting in front of a computer, the purpose of which is to make our lives easier.  Yes, you can run uuidgen on the command line and cut-and-paste into the IDE, but if you take just a few extra minutes and learn how to do some simple stuff with the built in macro editor you'll save yourself many extra minutes in the long run.

Filed under: , ,

Comments

# The Director of Random Technologies said on July 23, 2007 4:01 PM:

While I haven't been posting much here, I have been posting pretty regularly over on my main development

# Noticias externas said on July 23, 2007 5:01 PM:

While I haven't been posting much here, I have been posting pretty regularly over on my main development

Anonymous comments are disabled