Consulting

Results 1 to 4 of 4

Thread: Including the date in the subject and saving as msg in specific folder

  1. #1
    VBAX Newbie
    Joined
    Dec 2014
    Posts
    3
    Location

    Including the date in the subject and saving as msg in specific folder

    Is it possible to write a macro to copy the date I received the message, paste this date into the subject and save the message in a specific directory as .msg (no unicode)?

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Try this untested code.

    Sub SaveAsSubjectRecTimeMsg()
    
        Dim selectedEmail As MailItem
        Dim emailsub As String
    
        Set selectedEmail = ActiveExplorer.Selection.Item(1)
    
        emailsub = GetValidName(selectedEmail.subject & selectedEmail.ReceivedTime)
    
        With selectedEmail
            .SaveAs "C:\direcotry\folder\" & emailsub & ".msg", olSaveAsType.olMSG
        End With
    
    End Sub
    
    Function GetValidName(sSub As String) As String
    
        Dim sTemp As String
    
        sTemp = sSub
    
        sTemp = Replace(sTemp, "\", "")
        sTemp = Replace(sTemp, "/", "")
        sTemp = Replace(sTemp, ":", "")
        sTemp = Replace(sTemp, "*", "")
        sTemp = Replace(sTemp, """", "")
        sTemp = Replace(sTemp, "<", "")
        sTemp = Replace(sTemp, ">", "")
        sTemp = Replace(sTemp, "|", "")
    
        GetValidName = sTemp
    End Function
    More info here http://msdn.microsoft.com/en-us/libr...ice.15%29.aspx
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  3. #3
    VBAX Newbie
    Joined
    Dec 2014
    Posts
    3
    Location
    Thanks! It works well.

  4. #4
    VBAX Newbie
    Joined
    Dec 2014
    Posts
    3
    Location
    Quote Originally Posted by juliocba View Post
    Thanks! It works well.
    I had some problems because the "?" was missing in the function. I included it (sTemp = Replace(sTemp, "?", "") and it's ok now.

Tags for this Thread

Posting Permissions

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