我试图弄清楚如何通过将监听器放在该文件夹上来跟踪进入文件夹的邮件数量,但它无法正常工作。这是我所拥有的,但由于某种原因,当我将多个电子邮件拖到该文件夹时,所选金额不正确。基本上我正在尝试使用该文件夹将所有拖入其中的邮件项的名称更改为相同的名称。所以我需要能够引用那些被拖入的项目。我想我可以通过使用Selection来做到这一点,但我不确定。有任何想法吗??谢谢!这是我的代码:
Private WithEvents MatchTicketNumberItems As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
'Specify folders that will have listeners on them
Set MatchTicketNumberItems = objNS.GetDefaultFolder(olFolderInbox).Parent.Folders("MatchTicketNumber").Items
End Sub
Private Sub MatchTicketNumberItems_ItemAdd(ByVal item As Object)
Dim selected As Integer
Dim objSelection As Outlook.Selection
Set objSelection = Application.ActiveExplorer.Selection
selected = objSelection.count
'Do stuff
End Sub
答案 0 :(得分:0)
请记住,MAPI事件仅用于UI目的,并且可以(并且)在重负载下跳过。
话虽如此,你能更具体一点吗?您拖动了多少项以及事件处理程序触发了多少次?
另外,你为什么使用Explorer.Selection?如果直接创建项目,则当前选择将无关紧要。
答案 1 :(得分:0)
早期的答案解决了这个问题,但您可以尝试这种方式自动移动到MatchTicketNumber文件夹。
Private Sub MatchTicketNumberItems_ItemAdd(ByVal item As Object)
Dim objNS As Outlook.Namespace
Dim i As Long
' Do Stuff
item.Save
End Sub
Sub Process_Selection_Multiple_MatchTicketNumber()
Dim objNS As Outlook.Namespace
Dim targetFolder As MAPIFolder
Dim selectionIndex As Long
Dim itm As Object
Set objNS = Application.GetNamespace("MAPI")
Set targetFolder = objNS.GetDefaultFolder(olFolderInbox).Parent.Folders("MatchTicketNumber")
For selectionIndex = 1 To ActiveExplorer.Selection.count
Set itm = ActiveExplorer.Selection(selectionIndex)
itm.Move targetFolder
Next
End Sub