How to autosave the outlook attachments (Excel files) to a share drive folder without any manual work

Ganesh 1 Reputation point
2022-02-27T08:10:20.407+00:00

Like once we receive the emails from particular email and subject, the attachment should be autosaved to a share drive folder

Outlook | Windows | Classic Outlook for Windows | For business
{count} votes

2 answers

Sort by: Most helpful
  1. Neeraj S. Mishra 11 Reputation points
    2022-02-27T14:36:23.02+00:00

    Open the VBA IDE in Outlook. Alt-F11 will do this.
    Insert the following code to the Modules section. On the left side there is a tree, expand until you find Modules. Then, if there is not a Module item under Modules, create one by right clicking on Modules. Or right click and choose Insert -> Module.
    Now, paste the text below in the main VBA window.
    Close the VBA IDE.
    Create a Rule that calls the script. Tools -> Rules and Alerts -> New Rule...
    In the first screen of the new rule wizard, choose "Check messages when they arrive".
    In the second, you could specify certain criteria that the message must match. Tip: Try "with specific words in the message header" and ".txt" for the search string to save only .txt files.
    On the third screen, choose "run a script". When you click the underlined word, "script", you should see the code that you pasted in the VBA console.
    Click "finish", and test your work.

    Public Sub saveAttachtoDisk (itm As Outlook.MailItem)
    Dim objAtt As Outlook.Attachment
    Dim saveFolder As String
    saveFolder = "c:\temp\"
    For Each objAtt In itm.Attachments
    objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
    Set objAtt = Nothing
    Next
    End Sub

    2 people found this answer helpful.

  2. Steve Foster 1 Reputation point
    2022-11-03T04:50:15.63+00:00

    Hi @Neeraj S. Mishra ,

    I'm using Outlook 2016 and have pasted in the code to the VBA editor, but cannot see the option to run a macro from the rules menu

    Is there a way around this without having to go into the registry (a security issue at my company) or using the Data Gateway method?

    Thanks!
    Steve

    256588-rules.png


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.