Boris Brodski
Boris Brodski

Reputation: 8695

Delete attachment from an e-mail being edited

I'm writing a macro, that is designed to be run on an e-mail, that is currently being edited.

The problem I'm facing is, that I can't delete attachments. I get 80030002 error.

Here is my code

Set myItem = ActiveInspector.CurrentItem
c = myItem.Attachments.Count
For i = c To 1 Step -1
    Set myAttachment = myItem.Attachments.Item(i)
    If myAttachment.Type = OlAttachmentType.olByValue Then
        myItem.Attachments.Remove (i)
    End If
Next

After running this code, working deleting attachments manually results in a crash of Outlook.

My question is: How can I delete attachments from the e-mail being currently edited?

Microsoft Office Standard 2010

Upvotes: 2

Views: 124

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66215

Try the following instead :

Set myItem = Application.ActiveInspector.CurrentItem
set myAttachments = myItem.Attachments
c = myAttachments.Count
For i = c To 1 Step -1
    Set myAttachment = myAttachments.Item(i)
    If myAttachment.Type = OlAttachmentType.olByValue Then
        myAttachment.Delete
    End If
Next

Upvotes: 1

Related Questions