Date Stamp in SUBJECT BOX of Outgoing/Incoming Mail

G

Glen.Cooper

Does anyone know of a macro which will date and time stamp the subject
box of an incoming email? So if I were to get an email with the subject
as "-RE: CGTC - Drainage drawing-" I would like the macro to change the
subject to "-090802_15:46 RE: CGTC - Drainage drawing-". Todays date
with the time.

ALSO do the the same for outgoing emails, for example - I want to send
an email out and when I create a new email, already waiting in the
subject box is "090802_15:46" Todays date with the time.

ALSO, sorry - is there any macro out there which will allow me to open
an old email and date stamp it (in subject box) with the date and time
it was sent or recieved? I know I can open an old email and click into
the email and change this manually.... but I need a macro to do it.


Thank you for any help at all!!!

Glen
 
R

rattanjits

To stamp outgoing mails, save this script in ThisOutlookSession

Private Sub Application_ItemSend(ByVal Item As Object, Cancel A
Boolean)
If TypeName(Item) = MailItem Then
Dim strSubject As String
strSubject = Item.Subject
Item.Subject = strSubject & " " & Date & " " & Time
End If
End Sub


To stamp incoming mails, save this script in ThisOutlookSession

Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim myNameSpace As NameSpace
Dim myInbox As Folder
Dim myItem As Object
Dim strSubject As String
Set myNameSpace = Application.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
For i = 1 To myInbox.Items.Count
Set myItem = myInbox.Items.Item(i)
If myItem.EntryID = EntryIDCollection Then Exit For
Next
strSubject = myItem.Subject
myItem.Subject = strSubject & " " & Date & " " & Time
myItem.Save
End Sub

To stamp an old email, save this script in a Module. Run manually afte
selecting the email

Sub Date_Stamp_Subject()
Dim myItem As MailItem
Dim strsubject As String
Set myItem = GetCurrentItem()
myItem.Subject = strsubject & " " & Date & " " & Time
myItem.Save
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem
objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
End Select
Set objApp = Nothing
End Function

Regards
 
G

Glen.Cooper

Hi Rattanjits!

Thank you for the response, but none of that seems to work :-(

I have copied and pasted it all into the appropiate areas, and get the
error:

COMPILE ERROR:

EXPECTED: TYPE NAME

Can you help at all?
 
K

Ken Slovak - [MVP - Outlook]

If this is Outlook 2003 or earlier then change the declaration in
Application_NewMailEx() on the line:

Dim myInbox As folder

To this:

Dim myInbox As MAPIFolder

Make sure no lines are showing in red in case any line breaks were added
that split lines of code.

If that doesn't help then what line is highlighted on the error?

This is being put into the Outlook VBA project?
 
G

Glen.Cooper

Hi Ken,

Yes that has helped the code along. Thankyou!

Now there is a syntax error in Module1:

Set GetCurrentItem =

Any suggestions?

Glen
 
K

Ken Slovak - [MVP - Outlook]

Make sure no lines are showing in red in case any line breaks were added
that split lines of code.
 
G

Glen.Cooper

Hi Guys, thanks for all your help so far :)

Here below is the script which works well enough:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel A
Boolean)
If TypeName(Item) = "MailItem" Then
Dim strSubject As String
strSubject = Item.Subject
Item.Subject = Item.SenderName & " " & Date & " " & Item.Subject
End If
End Sub
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim myNameSpace As NameSpace
Dim myInbox As MAPIFolder
Dim myItem As Object
Dim strSubject As String
Set myNameSpace = Application.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
For i = 1 To myInbox.Items.Count
Set myItem = myInbox.Items.Item(i)
If myItem.EntryID = EntryIDCollection Then Exit For
Next
strSubject = myItem.Subject
myItem.Subject = myItem.SenderName & " " & Date & " " & myItem.Subject
myItem.Save
End Sub

Exceptions are that the macro does not seem to work unless the mail ha
been recieved while you are online and running OUTLOOK at the same time
Perhaps this macro has to be run from a constanlty working server t
make sure that ALL emails are date stamped.

For all those email that arrive out of hours or when you are not at th
machine, use:

Sub Date_Stamp_Subject()
Dim myItem As MailItem
Dim strSubject As String
Set myItem = GetCurrentItem()
myItem.Subject = myItem.SenderName & " " & myItem.CreationTime & " "
myItem.Subject
myItem.Save
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
End Select
Set objApp = Nothing
End Function

This works well, BUT it date stamps the mail with the information i
the following format - *SENDERNAME YYYYMMDD HHMMSS*. I definitelty d
not need this amount of information!

Does anyone know how I can reduce the stamp to this alone?

SENDERNAME YYMMD

Any help would be very much appreciated :)

Thanks again.

Gle
 
K

Ken Slovak - [MVP - Outlook]

Use the Format function for that. In this case you'd probably want the
format to look like this:

Format(date, "yymmdd")
 
G

Glen.Cooper

'Ken Slovak - [MVP - Outlook said:
;447425']Use the Format function for that. In this case you'd probabl
want the
format to look like this:

Format(date, "yymmdd")

--
Ken Slovak
[MVP - Outlook]
'Slovak Technical Services Home' (http://www.slovaktech.com)
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
'Slovak Technical Services Products
(http://www.slovaktech.com/products.htm)


Glen.Cooper said:
Hi Guys, thanks for all your help so far :)

Here below is the script which works well enough:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As
Boolean)
If TypeName(Item) = "MailItem" Then
Dim strSubject As String
strSubject = Item.Subject
Item.Subject = Item.SenderName & " " & Date & " " & Item.Subject
End If
End Sub
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim myNameSpace As NameSpace
Dim myInbox As MAPIFolder
Dim myItem As Object
Dim strSubject As String
Set myNameSpace = Application.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
For i = 1 To myInbox.Items.Count
Set myItem = myInbox.Items.Item(i)
If myItem.EntryID = EntryIDCollection Then Exit For
Next
strSubject = myItem.Subject
myItem.Subject = myItem.SenderName & " " & Date & " " myItem.Subject
myItem.Save
End Sub

Exceptions are that the macro does not seem to work unless the mai has
been recieved while you are online and running OUTLOOK at the sam time.
Perhaps this macro has to be run from a constanlty working server to
make sure that ALL emails are date stamped.

For all those email that arrive out of hours or when you are not a the
machine, use:

Sub Date_Stamp_Subject()
Dim myItem As MailItem
Dim strSubject As String
Set myItem = GetCurrentItem()
myItem.Subject = myItem.SenderName & " " & myItem.CreationTime & " &
myItem.Subject
myItem.Save
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
End Select
Set objApp = Nothing
End Function

This works well, BUT it date stamps the mail with the information in
the following format - *SENDERNAME YYYYMMDD HHMMSS*. I definitelt do
not need this amount of information!

Does anyone know how I can reduce the stamp to this alone?

SENDERNAME YYMMDD

Any help would be very much appreciated :)

Thanks again.

Glen


--
Glen.Cooper
------------------------------------------------------------------------
Glen.Cooper's Profile:
'The Code Cage Forums - View Profile: Glen.Cooper (http://www.thecodecage.com/forumz/member.php?userid=613)
View this thread:
'Date Stamp in SUBJECT BOX of Outgoing/Incoming Mail - The Code Cag
Forums' (http://www.thecodecage.com/forumz/showthread.php?t=121980)

Hi,

Can you tell me how to write into the code above a way to change th
format to YYYY/MM/DD please?

I cannot figure it out...

gle
 
K

Ken Slovak - [MVP - Outlook]

There is help for the Format function, you know.

You'd use something like this:

Format(date, "yyyymmdd")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top