Consulting

Results 1 to 3 of 3

Thread: Inserting Sent Date into subject line of all selected emails or within a folder

  1. #1
    VBAX Newbie
    Joined
    Sep 2016
    Posts
    2
    Location

    Inserting Sent Date into subject line of all selected emails or within a folder

    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!

  2. #2
    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
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Sep 2016
    Posts
    2
    Location
    Graham,

    Thank you very much - works perfectly!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •