The logic is as follows:
- Loop through selected messages.
- Loop through attachments of selected messages.
- Save attachments to pre-defined folder.
I am experiencing Runtime error 13.
I'm unsure which types are mismatched.
Public Sub SaveAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Set objOL = CreateObject("Outlook.Application")
Set objSelection = objOL.ActiveExplorer.Selection
For Each objMsg In objSelection
Set objAttachments = objMsg.Attachments
lngCount = objAttachments.Count
If lngCount > 0 Then
For i = 1 To lngCount
If objAttachments.Item(i).Type <> 5 Then
objAttachments.Item(i).SaveAsFile "C:\Users\Danny\Desktop\Attachments\" & objAttachments.Item(i).FileName
End If
Next i
End If
Next objMsg
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub