Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
La funzione permette di scaricare automaticamente uno o più file PDF allegati a una mail in ingresso in Outlook 2016. Consulta il blog per maggiori informazioni:
Attribute VB_Name = "SavePDFRule"
' Outlook 2016: Save all PDF Attachments
' -----------------------------------------------------------------------------------------------------------
' Author: GSolone
' Version: 0.1
' Based on: "Run a Script Rule to Save Attachments"
' (
' Info:
' Last modified: 28-09-2017
' Credits:
' ------------------------------------------------------------------------------------------------------------
' You'll need to set macro security to warn before enabling macros or
' sign the macro. You can change the folder name or path where the attachments
' are saved by editing the code.
' -
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 Desktop folder
strfolderpath = CreateObject("WScript.Shell").SpecialFolders(10)
strfolderpath = strfolderpath & "\Attachments\"
' Create directory Attachments if not exist
If Dir(strfolderpath, vbDirectory) = "" Then
MkDir strfolderpath
End If
' Save the file only if is a PDF
If InStr(strFile, ".pdf") Then
' Combine with the path to the folder.
strFile = strfolderpath & strFile
' Save the attachment as a file.
objAttachments.Item(i).SaveAsFile strFile
End If
Next i
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment