Outlook: save all attached files in a specified directory

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

Speaking about Microsoft Office Outlook 2007, in ThisOutlookSession I already have a set of rules to dispatch mails and attachments.

Now, I'd like to add a rule which, for a specified sender, saves all attachments in a directory.

Could something like this be correct?


VBA Code:
If Msg.SenderEmailAddress = "j.smith@abc.com" Then

        If Msg.Attachments.count > 0 Then

            For Each Attachment In Msg.Attachments

                        FileName = "Z:\Desktop\Folder1\" & Msg.Attachments.FileName
                        Msg.Attachments.SaveAsFile FileName

            Next

        End If
       
End If
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Except for a few syntax errors, it looks ok. I suspect you will encounter some more bugs in due course, though. The following should correct the syntax errors:

VBA Code:
If Msg.SenderEmailAddress = "j.smith@abc.com" Then
        If Msg.Attachments.count > 0 Then
            For Each objAttachment In Msg.Attachments
                        strFileName = "Z:\Desktop\Folder1\" & objAttachment.FileName
                        objAttachment.SaveAs strFilename
            Next
        End If       
End If

There are some other things that you may need to add to the code, but I would need to see the rest of the code before I could comment. Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,223,641
Messages
6,173,506
Members
452,518
Latest member
SoerenB

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top