Sskip已经分类邮件
当前代码:
Dim outlookapp Dim olns As Outlook.Namespace Dim Fldr As Outlook.MAPIFolder Dim olMail As Object 'Dim olMail As Outlook.MailItem Dim myTasks Dim projIDsearch As String Dim myrecipient As Outlook.Recipient Dim daysAgo As Long Set outlookapp = CreateObject("Outlook.Application") Set olns = outlookapp.GetNamespace("MAPI") Set myrecipient = olns.CreateRecipient("Ccbcphelpdesk") myrecipient.Resolve 'Set Fldr = olNs.GetDefaultFolder(olFolderInbox).Folders("ExemptionReview") Set Fldr = olns.GetSharedDefaultFolder(myrecipient, olFolderInbox) ' Restrict search to daysAgo daysAgo = 0 Set myTasks = Fldr.Items.Restrict("[ReceivedTime]>'" & Format(Date - daysAgo, "DDDDD HH:NN") & "'") projIDsearch = ActiveCell.Cells(1, 4) For Each olMail In myTasks If (InStr(1, olMail.Subject, projIDsearch, vbTextCompare) > 0) Then olMail.Categories = "ESP" olMail.Save End If Next end sub
这将查找与主题中的searchstring有关的电子邮件,然后将其标记为ESP。 我需要跳过已经分类的电子邮件。
我努力了:
If (InStr(1, olMail.Subject, projIDsearch, vbTextCompare) > 0) Then If olmail.categories Is nothing then 'line returns and error 424 olMail.Categories = "ESP" olMail.Save End If End If
我怎样才能跳过已经分类的电子邮件,只分类没有分类的电子邮件?
https://msdn.microsoft.com/en-us/library/office/ff860423.aspx
Categories
是一个stringtypes的属性,所以testing类似于:
If Len(olmail.Categories) = 0 Then
使用逻辑运算符And Not
你的限制方法
Set myTasks = Fldr.Items.Restrict("[ReceivedTime]>'" & Format(Date - daysAgo, "DDDDD HH:NN") & "' And Not [Categories] = 'ESP'")
并删除你的If olmail.categories Is nothing
办法,你不检查每个olmail
– 它应该olmail
你的循环