共享收件箱中收到的所有答复(RE :)和转发(FWD :)邮件必须自动移至“正在进行的文件夹”。当我在下面的代码中运行此代码时,它不起作用。
Private Sub Application_NewMail()
Dim olNameSpace As NameSpace
Set olNameSpace = GetNamespace("MAPI")
Dim olDestFolder As Folder
Set olDestFolder = olNameSpace.Folders("xxx@gmail.com").Folders("Ongoing")
Dim olLookUpFolder As Folder
Set olLookUpFolder = olNameSpace.Folders("xxx@gmail.com").Folders("Inbox")
' olMail is a Class. Avoid as a variable name
'Dim olMail As MailItem
Dim olObj As Object ' Outlook items are not necessarily mailitems
For Each olObj In olLookUpFolder.Items 'loop through Tickets folder to find original mail
If olObj.Class = olMail Then
Set objMail = objItem
v = objMail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10810003")
If (v = 102) Or (v = 104) Then
olObj.Move olDestFolder ' move to InProgress folder
Exit For
End If
End If
Next
End Sub
答案 0 :(得分:0)
首先,请勿对要修改的集合使用“ for each”(通过调用MailItem.Move
)。使用下循环。
第二,永远不要循环浏览文件夹中的所有项目(如果没有SELECT
子句,您就不会在SQL中使用WHERE
查询吗?)-使用Items.Find/FindNext
或{ {1}}
Items.Restrict: