question

AngeloMalfitano-2293 avatar image
0 Votes"
AngeloMalfitano-2293 asked DarrellPorter-0036 answered

Save attachment Outlook Desktop

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

office-outlook-itprooffice-itpro
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JadeLiang-MSFT avatar image
0 Votes"
JadeLiang-MSFT answered JadeLiang-MSFT commented

Hi @AngeloMalfitano-2293,

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.


image.png (11.5 KiB)
image.png (30.6 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @AngeloMalfitano-2293,

Could this script and rules work for your Outlook? If you still have any questions about my steps, please let me know and I would continue to research it with you.

0 Votes 0 ·
DarrellPorter-0036 avatar image
0 Votes"
DarrellPorter-0036 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.