Forum

Can I save attachme...
 
Notifications
Clear all

Can I save attachments in Outlook automatically? (e.g., use a rule setting of some sort?)

4 Posts
2 Users
0 Reactions
139 Views
(@johnsonmd)
Posts: 10
Eminent Member
Topic starter
 

Is there a way to tell Outlook to look for a specific parameter of an email (e.g., subject header) and then set a "rule" (or some sort of macro) for it to download the attached file(s) to a specified file folder when the rule is run?

Or do I need to pursue having the file-origination application put the file(s) in the folder?  (We haven't figured out how to do this yet, but we can get it to send an email attachment for use in our PowerPivot.)

 
Posted : 05/10/2016 5:29 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Marilyn,

You need some VBA to do this, and use a rule to trigger it.

First open your VBA editor from within Outlook by pressing ALT+F11.  On the left of the VBA editor window expand Microsoft Outlook Objects

Copy/paste this code into ThisOutlookSession

Option Explicit

Public Sub saveAttachtoDisk(itm As Outlook.MailItem)

    Dim objAtt As Outlook.Attachment
    
    Dim saveFolder As String
    Dim dateFormat
    
    dateFormat = Format(itm.ReceivedTime, "yyyy-mm-dd H-mm")
    saveFolder = "C:Temp"
    
    For Each objAtt In itm.Attachments
        
        objAtt.SaveAsFile saveFolder & dateFormat & objAtt.DisplayName
    
    Next
    
End Sub

Create a rule and specify the action as 'run a script'.  In the bottom part of the rule (Step 2 of the action) click the script link and choose this macro.

Continue though the rule creation to the end.

Go to the Outlook Options -> Trust Center -> Trust Center Settings -> Macro Settings and change it so that 'Notifications for all macros' is selected.  You can also sign the macro so you don't have to respond to a warning about running the macro.

Close Outlook and restart.

Open the rules and test it.

I found the above code here http://stackoverflow.com/questions/15531093/save-attachments-to-a-folder-and-rename-them and modified it very slightly.

Change the saveFolder in the code to whatever folder you like.

Phil

 
Posted : 06/10/2016 2:31 am
(@johnsonmd)
Posts: 10
Eminent Member
Topic starter
 

Thank you, Phil!  This worked great! 

I was able to save to my local C: drive. 
I was also able to save to a network share drive and to a SharePoint drive. 

The one warning I would add is to make sure the last "" is included in the saveFolder pathname at the end. (Ask me how I know.... Smile)

 
Posted : 06/10/2016 5:52 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

No worries, glad it worked for you.

Yes the trailing slash must be included in the saveFolder, otherwise there's no directory separator

Cheers

Phil

 
Posted : 06/10/2016 7:06 pm
Share: