Auto date on new mail message

I am trying to find out a method of automatically inserting the date (20070804-) in the subject line of a new outlook 2003 mail message.  On clicking "New Maiil Message" it should insert todays date (dynamically) in the subject line.  Ideally the format should be as per our IM plan YYYY/MM/DD (year/month/day).
davebain216Asked:
Who is Participating?
 
David LeeCommented:
Hi, davebain216.

The code below does what you've described.  Follow these instructions to use it.

1.  Start Outlook
2.  Click Tools->Macro->Visual Basic Editor.
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession.
4.  Copy the code and paste it into the right-hand pane of the VB Editor window.
5.  Edit the code as necessary.  I've placed comments where things need to change.
6.  Click the diskette icon on the toolbar to save the changes.
7.  Close the VB Editor.
8.  Click Tools->Macro->Security.
9.  Set the Security Level to Medium.
10.  Close Outlook.
11.  Start Outlook.
12.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run.  Say yes.


Public WithEvents olkInspectors As Outlook.Inspectors

Private Sub Application_Quit()
    Set olkInspectors = Nothing
End Sub

Private Sub Application_Startup()
    Set olkInspectors = Application.Inspectors
End Sub

Private Sub olkInspectors_NewInspector(ByVal Inspector As Inspector)
    Dim olkItem As Object
    Set olkItem = Inspector.CurrentItem
    If olkItem.Class = olMail Then
        If olkItem.Sent = False Then
            'Change the date format as needed.  You can add additional text to if desired.
            Inspector.CurrentItem.Subject = Format(Date, "YYYY/MM/DD")
        End If
    End If
    Set olkItem = Nothing
End Sub
0
 
peakpeakCommented:
The mail server automatically dates the messages, why would you want this as well?
Create a rule that performs a user defined action on sending, write a VB script that does what you want.
0
 
ScudboyCommented:
BlueDevilFan,

I ran across this thread because I am trying to accomplish the same concept to enforce new email standards. The code works great, but I would like to make one change though and I can't figure out how to do it.... How can I make it so the macro only auto inserts the subject on new emails only? The macro as it is right now erases the subject when you reply or forward a message.

Thanks!
0
 
David LeeCommented:
Hi, Scudboy.

Unfortunately, there is no message property that explicitly distinguishes a new message from a reply or forward.  Both new messages and replies/forwards represent unsent messages, so most of the properties are set the same.  We have to look elsewhere.  The Body property seems like it might distinguish a new message, new messages would be blank, but if the sender is using stationery or a signature, then that test fails.  The best test I can think of is to see if the Subject field is blank.  Of course some people send messages with blank subject lines, so it isn't a perfect test, but it's as close as I think we can get.  Try the revised module below.

Private Sub olkInspectors_NewInspector(ByVal Inspector As Inspector)
    Dim olkItem As Object
    Set olkItem = Inspector.CurrentItem
    If olkItem.Class = olMail Then
        If olkItem.Sent = False Then
            If olkItem.Subject = "" Then
                'Change the date format as needed.  You can add additional text to if desired.
                Inspector.CurrentItem.Subject = Format(Date, "YYYY/MM/DD")
            End If
        End If
    End If
    Set olkItem = Nothing
End Sub
0
 
David LeeCommented:
Is there anything else I can do to help with this question?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.