Avatar of bsharath
bsharath
Flag for India asked on

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

Hi,

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
\\servername\foldername\foldername

in the same way as now.
Regards
sharath
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 = "India.Alert@plc.com"
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
        Else
            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, " ")
            Next
            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
        Next
    End If
exitsub:
End Sub

Open in new window

Outlook

Avatar of undefined
Last Comment
bsharath

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Chris Bottomley

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
bsharath

ASKER
Thanks Chris that email comes in another 3 hrs..Shall check and get back
Chris Bottomley

Dont forget to modify the line:

saveFolder2

No offence intended ;o)
bsharath

ASKER
Sure
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
bsharath

ASKER
Thank U...:-)
bsharath

ASKER
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
bsharath

ASKER
Hi Chris any views...
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
bsharath

ASKER