首页 > 解决方案 > 如何从桌面目录中的所有电子邮件模板中删除特定收件人?

问题描述

我有一个 Outlook 消息的目录文件夹(桌面上的文件夹)(.msg)用作制作电子邮件的模板。

此文件夹中可能有 500 封电子邮件。我有时需要在每个月之后从每封电子邮件中删除一个特定的电子邮件地址。

Sub test()

Dim m As MailItem 'object/mail item iterator
Dim recip As Recipient 'object to represent recipient(s)
Dim email As Long

Set Remove = m.Remove

email = InputBox("Please enter the e-mail address you wish to remove")
answer = MsgBox("Are you sure you want to delete this e-mail?", vbYesNo + vbCritical, "Delete?")
If answer = vbYes Then

For Each m In Application.ActiveExplorer.Selection
If m.Class = olMail Then
Set Remove = m.Recipients.Remove(email)

End If

m.Save
End If

Next

End Sub

我如何用 VBA 做到这一点?

如果电子邮件有 johndoe@gmail.com,我希望在我在所有 TO、CC、BCC 等中运行此代码后删除该电子邮件。

标签: vbaoutlook

解决方案


调用Application.Session.OpenSharedItem每个 MSG 文件,删除收件人,调用MailItem.Save.


推荐阅读