Skip to content

Instantly share code, notes, and snippets.

@gildotdev
Created February 15, 2012 21:41
Show Gist options
  • Save gildotdev/1839180 to your computer and use it in GitHub Desktop.
Save gildotdev/1839180 to your computer and use it in GitHub Desktop.
This Outlook macro will allow you to append tags to the subject line of any message currently selected. To add a macro you must enable the developer menu in Outlook's options. This is based on code I found here http://www.vbaexpress.com/forum/showthread.
Attribute VB_Name = "Subject"
Sub AppendTags()
On Error Resume Next
Dim MsgColl As Object
Dim msg As Outlook.mailItem
Dim objNS As Outlook.NameSpace
Dim i As Long
Dim subjectname As String
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
' a collection of selected items
Set MsgColl = ActiveExplorer.Selection
Case "Inspector"
' only one item was selected
Set msg = ActiveInspector.CurrentItem
End Select
On Error GoTo 0
If (MsgColl Is Nothing) And (msg Is Nothing) Then
GoTo ExitProc
End If
subjectname = InputBox("What would you like to append to the subject?")
If Not MsgColl Is Nothing Then
For i = 1 To MsgColl.Count
' set an obj reference to each mail item so we can move it
Set msg = MsgColl.Item(i)
With msg
.Subject = .Subject & " " & subjectname
.Save
End With
Next i
ElseIf Not msg Is Nothing Then
msg.Subject = msg.Subject & " " & subjectname
End If
ExitProc:
Set msg = Nothing
Set MsgColl = Nothing
Set olMyFldr = Nothing
Set objNS = Nothing
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment