Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
La funzione permette di scaricare uno o più file PDF allegati a una o più mail già presenti in Outlook 2016 (tramite pulsante della barra multifunzione). Consulta il blog per maggiori informazioni:
Attribute VB_Name = "SavePDFButton"
' Outlook 2016: Save all PDF Attachments (Macro Button)
' -----------------------------------------------------------------------------------------------------------
' Author: GSolone
' Version: 0.1
' Based on: "Save Attachments to the hard drive"
' (
' 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 ExportAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String
' Get the path to your Desktop folder
strFolderpath = CreateObject("WScript.Shell").SpecialFolders(10)
On Error Resume Next
' Instantiate an Outlook Application object.
Set objOL = CreateObject("Outlook.Application")
' Get the collection of selected objects.
Set objSelection = objOL.ActiveExplorer.Selection
' Set the Attachment folder.
strFolderpath = strFolderpath & "\Attachments\"
' Create directory Attachments if not exist
If Dir(strFolderpath, vbDirectory) = "" Then
MkDir strFolderpath
End If
' Check each selected item for attachments.
For Each objMsg In objSelection
Set objAttachments = objMsg.Attachments
lngCount = objAttachments.Count
If lngCount > 0 Then
' Use a count down loop for removing items
' from a collection. Otherwise, the loop counter gets
' confused and only every other item is removed.
For i = lngCount To 1 Step -1
' Get the file name.
strFile = objAttachments.Item(i).FileName
' Combine with the path to the Temp folder.
strFile = strFolderpath & strFile
' Save the attachment as a file.
objAttachments.Item(i).SaveAsFile strFile
Next i
End If
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment