我的 Outlook 框中有一个 VBA 侦听器,用于在收到来自特定电子邮件的邮件时执行操作。
问题是,如果我收到错误邮件(未送达电子邮件),那么我的条件是在不具有该属性的邮件上运行,因此我的方法崩溃。
我也不知道主题是什么。
有谁知道我是否可以测试该属性是否存在,或者是否有其他属性可以检查以确定我的发件人是否匹配?
提前谢谢了
Sub SetFlagIcon()
Dim mpfInbox As Outlook.Folder
Dim obj As Outlook.MailItem
Dim i As Integer
Set mpfInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Test")
' Loop all items in the Inbox\Test Folder
For i = 1 To mpfInbox.Items.Count
If mpfInbox.Items(i).Class = olMail Then
Set obj = mpfInbox.Items.Item(i)
If obj.SenderEmailAddress = "[email protected] /cdn-cgi/l/email-protection" Then
'Set the yellow flag icon
obj.FlagIcon = olYellowFlagIcon
obj.Save
End If
End If
Next
End Sub
Dim obj as a generic Object
- 还有其他物体 MailItem
在你的收件箱中,也为了改善你的循环尝试使用 项目.限制方法(Outlook) https://learn.microsoft.com/en-us/office/vba/api/Outlook.Items.Restrict
Option Explicit
Sub SetFlagIcon()
Dim mpfInbox As Outlook.Folder
Dim obj As Object
Dim Items As Outlook.Items
Dim i As Long
Dim Filter As String
Set mpfInbox = Application.GetNamespace("MAPI").GetDefaultFolder _
(olFolderInbox).Folders("Temp")
Filter = "[SenderEmailAddress] = '[email protected] /cdn-cgi/l/email-protection'"
Set Items = mpfInbox.Items.Restrict(Filter)
' Loop all items in the Inbox\Test Folder
For i = 1 To Items.Count
If Items(i).Class = olMail Then
Set obj = Items(i)
'Set the yellow flag icon
obj.FlagIcon = olYellowFlagIcon
obj.Save
End If
Next
End Sub
Items.Restrict Method https://learn.microsoft.com/en-us/office/vba/api/Outlook.Items.Restrict Applies a filter to the Items https://learn.microsoft.com/en-us/office/vba/api/Outlook.Items.Restrict collection, returning a new collection containing all of the items from the original that match the filter.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)