Shami's Blog

Sysadmin, Because Even Developers Need Heroes

Signatures With Date Fields In Microsoft Outlook

2008-03-03

Ok, so today our CEO said he wanted everybody to stamp their emails with the sending date. It’s very simple to just add the date manually, but as you know, a good engineer is a lazy engineer. So this is how I did it:

Add “$$MYDATE$$” to your signature but without the quotes, then add this simple script to VBA:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If Item.Class = olMail Then
        Dim Signature As String
        Signature = Format(Now(), "d/m/yyyy")
        Item.HTMLBody = Replace(Item.HTMLBody, "$$MYDATE$$", Signature, , 1)
    End If
End Sub

This should do it. This script will replace $$MYDATE$$ with the current date as soon as you hit the “Send” button. So you will still see “$$MYDATE$$” while you’re typing the message.

Just make sure you lower the macro security to medium.

Hope that helps

About Me

Dev gone Ops gone DevOps. Any views expressed on this blog are mine alone and do not necessarily reflect the views of my employer.

twitter linkedin