Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Outlook macro that saves arrived emails attachments into a folder. want it to save in 2 placed rather than 1.


Outlook macro that saves arrived emails attachments into a folder. want it to save in 2 placed rather than 1.
At present it saves in the below path
Const saveFolder As String = "D:\SophosMailAttachments\"
Can i also save in this path

in the same way as now.
Sub SaveAttachment_NoStrip(ByRef mai As Outlook.MailItem)
Dim objItem As Object
Dim mailAtt As Attachment
Dim intAtt As Integer
Dim saver As String
Dim constsaver As String
Dim fn As String
Dim ft As String
Dim Subject As String
Dim del As Variant
Const sendereMailTrigger As String = ""
Const saveFolder As String = "D:\SophosMailAttachments\"
     On Error GoTo exitsub
     If LCase(mai.sendereMailAddress) <> LCase(sendereMailTrigger) Then Exit Sub
    If mai.Attachments.Count > 0 Then
        If Right(saveFolder, 1) = "\" Then
            constsaver = saveFolder
            constsaver = saveFolder & "\"
        End If
        constsaver = constsaver & Format(Date, "yyyy-mm-dd") & "\"
        md constsaver, True
        For intAtt = 1 To mai.Attachments.Count
            Subject = Replace(mai.ConversationTopic, """", " ")
            For Each del In Array("/", ":", "*", "?", "<", ">", "|")
                Subject = Replace(Subject, del, " ")
            Subject = Left(Subject, 250 - 16 - Len(constsaver))
            saver = constsaver & Subject & "_" & Left(mai.Attachments.Item(intAtt).FileName, InStr(mai.Attachments.Item(intAtt).FileName, ".") - 1) & "_" & Format(Date, "yyyy-mm-dd") & "." & Right(mai.Attachments.Item(intAtt).FileName, Len(mai.Attachments.Item(intAtt).FileName) - InStr(mai.Attachments.Item(intAtt).FileName, "."))
            mai.Attachments.Item(intAtt).SaveAsFile saver
    End If
End Sub

Open in new window

Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bsharath


Thanks Chris that email comes in another 3 hrs..Shall check and get back
Dont forget to modify the line:


No offence intended ;o)
Thank U...:-)
Chris i have a problem..

The 2nd location where the files are saved only happens if the folder is created manually...
Can the folder also get created in the 2nd path as the 1st location
Hi Chris any views...