Outlook macro to create work item and changeset hyperlinks

Buck Hodges

[NOTE: If this post looks truncated, scroll down or make the browser window wider.  The style sheet causes this.]

Ed Hintz, a dev lead on the TFS Version Control team, sends a lot of email with TFS work item numbers.  Work items can be viewed (not edited) in a web browser using an URL constructed from the server name and the work item number.  Our dogfood system is a single server, so the server is always the same.  So, Ed wrote a macro for Outlook that will convert the current selection to a hyperlink to the work item.

Here’s the code for the macro, which he bound to Alt+L.  The hyperlinks generated will work for beta 3, but you would need to tweak the hyperlink for earlier releases.

Sub LinkToWorkItem()

‘ Convert the current selection to a work item hyperlink

    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
        “http://TFserver:8080/WorkItemTracking/Workitem.aspx?artifactMoniker=” _
& Selection.Text, _
        SubAddress:=””, ScreenTip:=””, TextToDisplay:=Selection.Text
End Sub

To do the same thing for changesets, use the following.

Sub LinkToChangeset()

‘ Convert the current selection to a changeset hyperlink

    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
        “http://TFserver:8080/VersionControl/VersionControl/Changeset.aspx?artifactMoniker=” _
& Selection.Text & “&webView=true” _
        , SubAddress:=””, ScreenTip:=””, TextToDisplay:=Selection.Text
End Sub

If you have never created a macro in Outlook, create a new mail message, click in the body (otherwise, the Macros menu is disabled), go to Tools -> Macro -> Macros, enter the name “LinkToWorkItem” in the dialog’s text box, and click Create.  In the Visual Basic Editor that opens up, paste the body of the LinkToWorkItem macro into the subroutine, save, and close the VB Editor.  To associate it with Alt+L, go to Tools -> Customize, click the Keyboard button, scroll down to Macros in the Categories list box, click in the “Press new shortcut key” text box, and press Alt+L.  Now click Assign, Close, and Close.  In the new mail message you have up, type a number, select it, and hit Alt+L to test it.

Now when you want to turn a plain number into a work item or changeset link, highlight the number and run the macro via the shortcut you’ve assigned.

[Update 10/03/05]  Updated code comment.

0 comments

Leave a comment

Feedback usabilla icon