How can i extract attachments to a folder automatically in Microsoft Outlook 2016?

Print article Email to friend
0.00

Rule to automatically save attachment in Outlook

  1. Open the VBA IDE in Outlook. Alt-F11 will do this.
  2. 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.
  3. Now, paste the text below in the main VBA window. - Change the saveFolder option to a folder of your choosing.

    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

  4. Close the VBA IDE.
  5. Create a Rule that calls the script. Tools -> Rules and Alerts -> New Rule...
  6. In the first screen of the new rule wizard, choose "Check messages when they arrive".
  7. 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.
  8. 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.
  9. Click "finish", and test your work.

 

If you want to save attachments of a certain kind only (for example, XML files), you can use this bit of code inside of the "For Each" loop (instead of the code provided above):

if InStr(objAtt.DisplayName, '.xml') Then

          objAtt.SaveAsFile saveFolder & "" & objAtt.DisplayName

 

Having Problems? Try adjusting your Outlook security settings:

  1. On the Filetab, choose Outlook Options to open the Outlook Options dialog box, and then click Trust Center.
  2. Click Trust Center Settings, and then the Macro Settingsoption on the left.
  3. Select Notifications for all macrosand then click OK. The option allows macros to run in Outlook, but before the macro runs, Outlook prompts you to verify that you want to run the macro.
  4. Restart Outlook for the configuration change to take effect.

Not seeing the "Run A Script" Option in the rules?

To restore the missing run a script option in the Outlook rules wizard, please do as follows:

  1. 1. Press WinRkeys together to open the Run dialog box, in the dialog box type regedit in the Open box, and click the OK See screenshot:
  2. 2. In the popping out User Account Control dialog box, please click the Yes  See screenshot:
  3. 3. In the Registry Editor window, please open the Securitykey with below path:
    HKEY_CURRENT_USERSoftwareMicrosoftOffice16.0OutlookSecurity
  4. 4. Right click the Securitykey, and select NewDWORD (32-BIT Value) from the right-clicking menu, and then name the new DWORD as EnableUnsafeClientMailRules. See screenshot:
  5. 5. Double click the EnableUnsafeClientMailRulesDWORD to open the Edit QWORD Value dialog box. See screenshot:
  6. 6. In the Edit QWORD (64-BIT) Value dialog box, type 1in the Value databox, and click the OK See screenshot above.
  7. 7. Restart your Microsoft Outlook.

And now you will find out the run a script option in the Step 1: Select action (s) of Rules Wizard.

 

How can i extract attachments to a folder automatically in Microsoft Outlook 2016?

Rule to automatically save attachment in Outlook

  1. Open the VBA IDE in Outlook. Alt-F11 will do this.
  2. 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.
  3. Now, paste the text below in the main VBA window. - Change the saveFolder option to a folder of your choosing.

    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

  4. Close the VBA IDE.
  5. Create a Rule that calls the script. Tools -> Rules and Alerts -> New Rule...
  6. In the first screen of the new rule wizard, choose "Check messages when they arrive".
  7. 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.
  8. 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.
  9. Click "finish", and test your work.

 

If you want to save attachments of a certain kind only (for example, XML files), you can use this bit of code inside of the "For Each" loop (instead of the code provided above):

if InStr(objAtt.DisplayName, '.xml') Then

          objAtt.SaveAsFile saveFolder & "" & objAtt.DisplayName

 

Having Problems? Try adjusting your Outlook security settings:

  1. On the Filetab, choose Outlook Options to open the Outlook Options dialog box, and then click Trust Center.
  2. Click Trust Center Settings, and then the Macro Settingsoption on the left.
  3. Select Notifications for all macrosand then click OK. The option allows macros to run in Outlook, but before the macro runs, Outlook prompts you to verify that you want to run the macro.
  4. Restart Outlook for the configuration change to take effect.

Not seeing the "Run A Script" Option in the rules?

To restore the missing run a script option in the Outlook rules wizard, please do as follows:

  1. 1. Press WinRkeys together to open the Run dialog box, in the dialog box type regedit in the Open box, and click the OK See screenshot:
  2. 2. In the popping out User Account Control dialog box, please click the Yes  See screenshot:
  3. 3. In the Registry Editor window, please open the Securitykey with below path:
    HKEY_CURRENT_USERSoftwareMicrosoftOffice16.0OutlookSecurity
  4. 4. Right click the Securitykey, and select NewDWORD (32-BIT Value) from the right-clicking menu, and then name the new DWORD as EnableUnsafeClientMailRules. See screenshot:
  5. 5. Double click the EnableUnsafeClientMailRulesDWORD to open the Edit QWORD Value dialog box. See screenshot:
  6. 6. In the Edit QWORD (64-BIT) Value dialog box, type 1in the Value databox, and click the OK See screenshot above.
  7. 7. Restart your Microsoft Outlook.

And now you will find out the run a script option in the Step 1: Select action (s) of Rules Wizard.