Date Stamp in SUBJECT BOX of Outgoing/Incoming Mail

Status
Not open for further replies.
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
 
To stamp outgoing mails, save this script in ThisOutlookSession




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 = 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 after 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,
 
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?

--
 
Try this:

If TypeName(Item) = "MailItem" Then

 
Hi Ken,

Sorry, same error :-(

Anything else?

Glen

Glen.Cooper

----------------------------------------Glen.Cooper's Profile: userid=613
?t=121980
 
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?

 
Hi Ken,

Yes that has helped the code along. Thankyou!

Now there is a syntax error in Module1:

Set GetCurrentItem =

Any suggestions?

Glen

--
 
Make sure no lines are showing in red in case any line breaks were added

that split lines of code.

 
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 mail has

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 to

make sure that ALL emails are date stamped.

For all those email that arrive out of hours or when you are not at 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 definitelty 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
 
Use the Format function for that. In this case you'd probably want the

format to look like this:

Format(date, "yymmdd")

 
Hi,

Can you tell me how to write into the code above a way to change the

format to YYYY/MM/DD please?

I cannot figure it out...

glen
 
There is help for the Format function, you know.

You'd use something like this:

Format(date, "yyyymmdd")

 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Macro to add date/time stamp to subject Outlook VBA and Custom Forms 4
L Ctrl Alt d date stamp use Using Outlook 1
J Command Button to stamp a date and time in a textbox in Outlook 2016 Outlook VBA and Custom Forms 3
0 Add a date stamp to the note field of a custom form Outlook VBA and Custom Forms 1
N How to extract date and time stamp from messsages Outlook VBA and Custom Forms 6
F Outlook 365 Group INBOX by date but not by date and time Using Outlook 1
S Displaying Date Value In Formula Outlook VBA and Custom Forms 6
CWM550 Wrong Date Using Outlook 4
C Outlook 365 Copy/Save Emails in Folder Outside Outlook to Show Date Sender Recipient Subject in Header Using Outlook 0
R unable to filter tasks when start date is on or before today Using Outlook 3
S Combination Field (Date Format) Outlook VBA and Custom Forms 0
U How can the Received date be edited? Using Outlook 0
D This folder up to date vs all folders up to date Using Outlook 1
S Outlook Macro for [Date][Subject] Using Outlook 1
N Save emails within a certain date range to network drive Outlook VBA and Custom Forms 0
kburrows Reset Date to Keep Tasks from Archiving Using Outlook 9
M Extract "Date sent" from emails (saved to folder using drag and drop) Outlook VBA and Custom Forms 1
DDB VBA to Auto Insert Date and Time in the signature Outlook VBA and Custom Forms 2
P Short Date Format when typing in a task Using Outlook 2
S Change "This Week" flag start date behavior Using Outlook 1
S Archiving and Likely Modified Date Problem Using Outlook 3
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
S Outlook 2016 Arrange tasks by date, additional custom sorting, but still use friendly terms like Today, Tomorrow, This week? Using Outlook 1
L Macro to add Date & Time etc to "drag to save" e-mails Outlook VBA and Custom Forms 17
S save attachment with date & time mentioned inside the file Outlook VBA and Custom Forms 0
Witzker Pls help to change the code for inserting date in Ol contact body Outlook VBA and Custom Forms 5
C Outlook with Office365 - search across account, by date rate, in multiple folders - how? Using Outlook 2
M Sorting by Day in Date Column Advanced Filter BCM (Business Contact Manager) 1
V Date and/or time error in Outlook Form Outlook VBA and Custom Forms 0
S Body text of Email from invite date/time Outlook VBA and Custom Forms 7
V 10 Years calenders -single date together Exchange Server Administration 8
O Export Outlook calendar appointments by filters and date range Outlook VBA and Custom Forms 1
D Add date next to day name in Outlook Today calendar view Using Outlook 1
X If you change expiration date of repeated task it dupplicates Using Outlook 1
D Archive by receive date not working Using Outlook 2
V Making a Date field mandatory in outlook form Outlook VBA and Custom Forms 2
P Auto Insert Current Date or Time into Email Subject Outlook VBA and Custom Forms 2
A Create date folder and move messages daily Outlook VBA and Custom Forms 1
Witzker Outlook 2010 Insert Date & Time at the button of an OL contactform in red Using Outlook 2
O Tasks - Is there a postponed date column? Using Outlook 7
K Outlook Archive to PST Files by Date Range VBA Script? Outlook VBA and Custom Forms 1
W Save and rename outlook email attachments to include domain name & date received Outlook VBA and Custom Forms 4
F Finding Meetings/Tasks in a date range Using Outlook 1
W Save Outlook attachment in network folder and rename to current date and time Outlook VBA and Custom Forms 18
V Changing default date for task follow-up buttons Using Outlook 2
J Old unread emails on current date (MDaemon Server) Using Outlook 1
D Outlook macro with today's date in subject and paste clipboard in body Outlook VBA and Custom Forms 1
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
B Search by date macro Outlook VBA and Custom Forms 0
S set a flag task date as the next weekday Outlook VBA and Custom Forms 4

Similar threads

Back
Top