Save attachment Outlook Desktop

Angelo Malfitano 46 Reputation points
2021-07-23T05:22:27.897+00:00

Hello,

I need a macro to save all attachment from particular sender with a particular subject into my folder.

How do it?

Thanks for support

Nik

please note: outlook version 365 desktop

Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
4,900 questions
Office Management
Office Management
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Management: The act or process of organizing, handling, directing or controlling something.
2,010 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Darrell Porter 6 Reputation points
    2021-09-21T21:14:58.937+00:00

    This does not work. I have set the rule to run the above script yet the script never runs and no attachments are ever saved to a known-existing folder.

    Outlook 365 on Windows 10.

    1 person found this answer helpful.
    0 comments No comments

  2. Jade Liang-MSFT 9,956 Reputation points Microsoft Employee
    2021-07-23T09:05:07.117+00:00

    Hi @Angelo Malfitano ,

    Please first understand here we mainly focus on general issues on Outlook desktop client, for your script issue, I have researched a lot and found we could set a rule with specific conditions(such as particular sender and subject) and run a script in it like below to meet it.

    According to my tests, it could work on my Outlook 365, here are my detailed steps:

    1. create a new folder named"Attachments" under my Document to save the attachment
      117400-image.png
    2. paste the script in ThisOutlookSession VBA(Alt+F11) Public Sub SaveAttachments(Item As Outlook.MailItem) If Item.Attachments.Count > 0 Then Dim objAttachments As Outlook.Attachments
      Dim lngCount As Long
      Dim strFile As String
      Dim sFileType As String
      Dim i As Long Set objAttachments = Item.Attachments
      lngCount = objAttachments.Count
      For i = lngCount To 1 Step -1 ' Get the file name.
      strFile = objAttachments.Item(i).FileName ' Get the path to your My Documents folder
      strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
      strFolderpath = strFolderpath & "\Attachments\" ' Combine with the path to the folder.
      strFile = strFolderpath & strFile ' Save the attachment as a file.
      objAttachments.Item(i).SaveAsFile strFile Next i
      End If End Sub
    3. create a rule and set the condition(Rules>Manage rules and Alerts>New Rule>Apply rule on message I receive>set from particular sender with a particular subject>choose run a script> choose your script)
      117405-image.png

    Notice: If you don't have the "run a script" option in rules, you could try to set the register key like below

    HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security
    DWORD: EnableUnsafeClientMailRules
    Value: 1
    (Note: Serious problems can occur if you modify the registry incorrectly. Before making changes, back up the registry to restore it in case something goes wrong.)

    Hope that would be helpful to you.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.