Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-29-2014, 01:50 AM
gmayor's Avatar
gmayor gmayor is offline export emails Windows 7 64bit export emails Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

When you drag a message to the desktop you essentially save it as a message file. You can do that instead with a macro that will name the file including the received date etc in the filename. Change the path from "C:\Path\" to a suitable location (the desktop is not ideal) and run GetMsg with the message in question selected. The additional function will ensure that files which would duplicate names are preserved. e.g.



20141129 03.48 Sender - Subject.msg
20141129 03.48 Sender - Subject(1).msg

Code:
Option Explicit
Sub GetMsg()
Dim olMsg As MailItem
    On Error Resume Next
    Set olMsg = ActiveExplorer.Selection.Item(1)
    SaveMessage olMsg
End Sub

Sub SaveMessage(olItem As MailItem)
Dim Fname As String
Const fPath As String = "C:\Path\"

            Fname = Format(olItem.ReceivedTime, "yyyymmdd") & Chr(32) & _
                    Format(olItem.ReceivedTime, "HH.MM") & Chr(32) & olItem.SenderName & " - " & olItem.Subject
            Fname = Replace(Fname, Chr(58) & Chr(41), "")
            Fname = Replace(Fname, Chr(58) & Chr(40), "")
            Fname = Replace(Fname, Chr(34), "-")
            Fname = Replace(Fname, Chr(42), "-")
            Fname = Replace(Fname, Chr(47), "-")
            Fname = Replace(Fname, Chr(58), "-")
            Fname = Replace(Fname, Chr(60), "-")
            Fname = Replace(Fname, Chr(62), "-")
            Fname = Replace(Fname, Chr(63), "-")
            Fname = Replace(Fname, Chr(124), "-")
            SaveUnique olItem, fPath, Fname
End Sub

Private Function SaveUnique(oItem As Object, _
                           strPath As String, _
                           strFilename As String)
Dim lngF As Long
Dim lngName As Long
    lngF = 1
    lngName = Len(strFilename)
    Do While FileExists(strPath & strFilename & ".msg") = True
        strFilename = Left(strFilename, lngName) & "(" & lngF & ")"
        lngF = lngF + 1
    Loop
    oItem.SaveAs strPath & strFilename & ".msg"
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Export to Pdf JohnBi Word VBA 0 07-06-2013 11:12 PM
Export Outlook emails to Access & parse certain text elements smahale Outlook 0 01-18-2012 09:30 PM
export emails Import and Export of emails JiminSA Outlook 2 07-21-2011 04:22 AM
export emails Outlook emails are marked as spam, but Gmail emails are not. aquabob Outlook 1 07-28-2010 11:41 AM
export outlook express emails to an account within outlook 2003 zillah Outlook 0 11-23-2009 03:20 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft