Kumshan1988
New Member
Currently below vba code auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox
I want to do modifications in below code so that it only auto downloads email into a specific folder in local hard disk as and when any new email arrives in inbox/subfolder (For eg: ApprovalMails in my scenario). I dont know where to change the code to get the desired output. please help.
>>> use code - tags <<<
I want to do modifications in below code so that it only auto downloads email into a specific folder in local hard disk as and when any new email arrives in inbox/subfolder (For eg: ApprovalMails in my scenario). I dont know where to change the code to get the desired output. please help.
>>> use code - tags <<<
Code:
Public Sub SaveMsg(Item As Outlook.MailItem)
Dim sPath As String
Dim dtDate As Date
Dim sName As String
Dim enviro As String
enviro = CStr(Environ("USERPROFILE"))
sName = Item.Subject
ReplaceCharsForFileName sName, "_"
dtDate = Item.ReceivedTime
sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
vbUseSystem) & Format(dtDate, "-hhnnss", _
vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName & ".msg"
' use My Documents in older Windows.
sPath = enviro & "\Documents\ApprovalMails\"
Debug.Print sPath & sName
Item.SaveAs sPath & sName, olMSG
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, Chr(34), sChr)
sName = Replace(sName, "<", sChr)
sName = Replace(sName, ">", sChr)
sName = Replace(sName, "|", sChr)
End Sub
Sub aagdsa()
End Sub
Last edited by a moderator: