从正在编辑的电子邮件中删除附件

时间:2016-05-31 09:58:19

标签: vba outlook outlook-vba outlook-2010

我正在编写一个宏,该宏旨在通过电子邮件运行,目前正在编辑

我面临的问题是,我无法删除附件。我得到 80030002 error

这是我的代码

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

运行此代码后,手动删除附件会导致Outlook崩溃。

我的问题是:如何从当前编辑的电子邮件中删除附件?

Microsoft Office Standard 2010

1 个答案:

答案 0 :(得分:1)

请尝试以下方法:

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