Vamos a crear una macro que salve a una carpeta específica todos los archivos adjunto de un mensaje o de varios mensajes sin necesidad de abrirlos.
Editor de Visual Basic
Abrimos el editor pulsando ALT+F11.
Ventana de proyectos
A la izquierda tenemos la ventana de proyectos. Hacemos doble clic en ThisOutlookSession.
Pegado de código
En la sección de edición pegamos el código que se reproduce abajo en azul. La macro se llamará SavenotdeleteAttachments (no elimina los archivos del cuerpo del mensaje)
Public Sub SavenotdeleteAttachments()
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 My Documents folder
strFolderpath = "C:\adjuntos\"
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
' The attachment folder needs to exist
' You can change this to another folder name of your choice
' Set the Attachment folder.
strFolderpath = strFolderpath
' 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
Next
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub
Public Sub SavenotdeleteAttachments()
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 My Documents folder
strFolderpath = "C:\adjuntos\"
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
' The attachment folder needs to exist
' You can change this to another folder name of your choice
' Set the Attachment folder.
strFolderpath = strFolderpath
' 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
Next
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub
Salvamos
Clic en el disco o Control+S para salvar el proyecto.
Creación de carpeta "adjuntos"
Ese código presupone que existe una carpeta llamada "adjuntos" en la unidad C: . Como lo más probable es que no la tengamos debemos crearla puesto que aquí se salvarán los archivos adjuntados.
Seleccionar mensajes con adjuntos
Con la macro creada bastará con seleccionar los mensajes con adjuntos que deseemos guardar sin necesidad de abrirlos individualmente.
ALT+F8, Caja de diálogo de macros
Sin que se pierda la selección pulsamos ALT+F8 para activar la caja de macros. Seleccionamos nuestra macro, en este caso la última, y hacemos clic en ejecutar.
Archivos salvados en la carpeta adjuntos
Ya está, los archivos aparecerán salvados en esa carpeta. Esta macro resulta de gran utilidad cuando pretendamos salvar decenas de adjuntos de muchos mensajes.
Botón en la barra de menús
Podemos añadir el botón de la macro en la barra de menús para mayor comodidad.