Hi all,
I found some code on the web and am trying to adapt it. I need to categorize and save emails by their subject and time received so that I can reference them in a database. The below code works for new emails, but when i try to save someone's reply it creates an empty file.
I found some code on the web and am trying to adapt it. I need to categorize and save emails by their subject and time received so that I can reference them in a database. The below code works for new emails, but when i try to save someone's reply it creates an empty file.
VBA Code:
Public Sub SaveMessageAsMsg()
Dim oMail As Outlook.MailItem
Dim objItem As Object
Dim sPath, strFolderpath As String
Dim dtDate As Date
Dim sName As String
Dim enviro As String
'enviro = CStr(Environ("USERPROFILE"))
strFolderpath = "C:\Alex\Documents\EMAILS"
sPath = strFolderpath & "\"
For Each objItem In ActiveExplorer.Selection
If objItem.MessageClass = "IPM.Note" Then
Set oMail = objItem
sName = oMail.Subject
dtDate = oMail.ReceivedTime
sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
vbUseSystem) & Format(dtDate, "-hhnnss", _
vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName & ".msg"
Debug.Print sPath & sName
oMail.SaveAs sPath & sName, olMSG
End If
Next
End Sub