1
votes

I'm trying to create a macro to download attachments from email I recieve and THEN delete the email.

I've got the macro to download the attachment, however, I don't know how to make it delete the email AFTER it downloads. When I use a rule, it deletes the email BEFORE downloading the attachment.

Here's what I've got:

Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "S:\Training and Curriculum\Staff Training Files\01 scans\"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub
1
Just use MItem.Delete - 0m3r

1 Answers

1
votes

From what I can tell on that sub, you are passing MItem as the Outlook.MailItem object, which if I read your question correctly, is the item you want deleted. After your next in your loop, you should just be able to do MItem.Delete, which will delete that particular item after saving the file.

Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)

Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "S:\Training and Curriculum\Staff Training Files\01 scans\"

For Each oAttachment In MItem.Attachments
    oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next

MItem.Delete 'This is the delete command

End Sub

Here is the MSDN documentation on MailItem.Delete - MSDN MailItem Delete Method