+ Reply to Thread
Results 1 to 1 of 1

Save Email into specific folder with file name from body of email

  1. #1
    Forum Contributor
    Join Date
    05-04-2016
    Location
    London
    MS-Off Ver
    MS Office Excel 2010/2013
    Posts
    339

    Save Email into specific folder with file name from body of email

    Hi Forum experts,

    I have this requirement that is quite simple .. however I have a code already with me . it save email copy into my folder with file name as " date and subject of the email" . to be more dynamic I want small change in the file name to save with " Memo number " that has come in the email body" .

    attached is the file for your reference .

    HTML Code: 
    Public Sub SaveMessageAsMsg()
      Dim oMail As Outlook.MailItem
      Dim objItem As Object
      Dim sPath As String
      Dim dtDate As Date
      Dim sName As String
      Dim enviro As String
     
        enviro = CStr(Environ("USERPROFILE"))
       For Each objItem In ActiveExplorer.Selection
       If objItem.MessageClass = "IPM.Note" Then
        Set oMail = objItem
       
      sName = oMail.Subject
      ReplaceCharsForFileName sName, "-"
     
      dtDate = oMail.ReceivedTime
      sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
        vbUseSystem) & Format(dtDate, "-hhnnss", _
        vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName & ".msg"
         
        sPath = enviro & "\Documents\"
      Debug.Print sPath & sName
      oMail.SaveAs sPath & sName, olMSG
      
      End If
      Next
      
    End Sub
     
    Private Sub ReplaceCharsForFileName(sName As String, _
      sChr As String _
    )
      sName = Replace(sName, "'", sChr)
      sName = Replace(sName, "*", sChr)
      sName = Replace(sName, "/", sChr)
      sName = Replace(sName, "\", sChr)
      sName = Replace(sName, ":", sChr)
      sName = Replace(sName, "?", sChr)
      sName = Replace(sName, Chr(34), sChr)
      sName = Replace(sName, "<", sChr)
      sName = Replace(sName, ">", sChr)
      sName = Replace(sName, "|", sChr)
    End Sub
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy and paste body of unread email from a specific folder to excel
    By Teblol in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-19-2016, 04:04 PM
  2. look for text in email body and move email to a folder
    By Megatronixs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-10-2015, 05:23 AM
  3. vba didnt save all email into specific folder
    By gingank in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-02-2014, 07:08 AM
  4. [SOLVED] sending email with specific range as email body vba modification
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-19-2014, 11:24 AM
  5. Replies: 0
    Last Post: 09-12-2013, 07:43 AM
  6. Replies: 0
    Last Post: 02-21-2013, 04:46 AM
  7. [SOLVED] Create folder, save as pdf, and email file
    By af_lel in forum Excel Programming / VBA / Macros
    Replies: 31
    Last Post: 02-05-2013, 07:35 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1