Currently attempting to write a simple script to save attachments from mails coming in from a specific email address to a folder, and then remove all attachments from the copy of the mail stored in outlook in order to reduce bloat. The saving part works but the attachments are not removed from the stored mail. Is something wrong with my code ?
Sub SaveAttachmentsFromSelectedItemsPDF(Item As Outlook.MailItem)
Set attachs = Item.Attachments
Dim currentAttachment As Outlook.Attachment
Dim i As Long
For i = attachs.Count To 1 Step -1
Set currentAttachment = attachs.Item(i)
If UCase(Right(currentAttachment.DisplayName, 4)) = ".PDF" Then
file = currentAttachment.FileName
currentAttachment.SaveAsFile "C:test" & file
Item.Attachments.Remove i
End If
Next
Item.Save
End Sub
I have tried multiple formats (including putting the i in parenthesis) as well as deleting “CurrentAttachment” every loop to no avail.
Croque-Monsieur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.