PDA

View Full Version : [SOLVED:] Inserting Sent Date into subject line of all selected emails or within a folder



jke89
09-05-2016, 08:23 AM
Hey guys,

I am looking for a VBA code that changes the subject line of a group of selected emails, OR all emails in a specific folder - whichever is easiest - so that the date that the email was sent is at the start of the subject.

I have a folder of emails to file each month so I have to insert the sentdate at the start of the subject line, save, and close, and move onto the next.

The format of the date should be YYYY.MM.DD


Thank you for your help!

gmayor
09-05-2016, 09:02 PM
Neither is more difficult than then other - code for both below:


Option Explicit

Sub AddDate()
Dim olItem As MailItem
Dim strDate As String
On Error GoTo lbl_Exit
For Each olItem In Application.ActiveExplorer.Selection
strDate = Format(olItem.ReceivedTime, "yyyy.mm.dd - ")
olItem.subject = strDate & olItem.subject
olItem.Save
Next olItem
lbl_Exit:
Set olItem = Nothing
Exit Sub
End Sub

Sub AddDate2()
Dim olItem As MailItem
Dim olFolder As Folder
Dim strDate As String
On Error GoTo lbl_Exit
Set olFolder = Session.PickFolder
For Each olItem In olFolder.Items
strDate = Format(olItem.ReceivedTime, "yyyy.mm.dd - ")
olItem.subject = strDate & olItem.subject
olItem.Save
Next olItem
lbl_Exit:
Set olItem = Nothing
Exit Sub
End Sub

jke89
09-06-2016, 12:42 AM
Graham,

Thank you very much - works perfectly!