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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
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,214,606
Messages
6,120,483
Members
448,967
Latest member
visheshkotha

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