VBA Outlook活动移动电子邮件 [英] VBA Outlook event moving email
问题描述
我搜索一个方法来获取展望中的移动项目/电子邮件的事件。
I search a way to get the event of a moving item/email in outlook.
我们可以使用检查器吗?
或者也许有一个事件处理程序,如项目或新邮件?
Can we use an Inspector? Or maybe there's an event handler like itemsent or newmail?
谢谢
更多详细信息:
我有4个或更多的邮箱。
每个文件夹和子文件夹的数量为X(其中1个是具有数百万个文件夹的活动链接框)。
有些是常见的盒子,有人拖拽普通邮件。
I have 4 or more mail boxes. Each has an number X of folders and subfolders (1 of them is a livelink box with millions of folders). Some are common box, and there are people who drag common mail.
我想在每次邮件在livelink框中的文件夹上移动时捕获。
I want to catch every time a mail is moved on a folder in livelink box.
推荐答案
当将项目添加到文件夹中的集合时,会触发事件。例如,假设您的默认收件箱下方有一个名为Stuff的文件夹。每次将电子邮件移动到该文件夹时,此代码将触发:
An event is fired when an item is added to a collection, in a folder. For example, suppose you had a folder called "Stuff" one level below your default Inbox. This code would fire every time an email was moved to that folder:
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Set olApp = Outlook.Application
Set Items = GetNS(olApp).GetDefaultFolder(olFolderInbox).Folders("Stuff").Items
End Sub
Private Sub Items_ItemAdd(ByVal item As Object)
On Error GoTo ErrorHandler
MsgBox "You moved an item into the 'Stuff' folder."
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Function GetNS(ByRef app As Outlook.Application) As Outlook.NameSpace
Set GetNS = app.GetNamespace("MAPI")
End Function
将其粘贴到ThisOutlookSession并重新启动Outlook。每当电子邮件被移动到该文件夹时,您将看到弹出窗口。
Paste this into ThisOutlookSession and restart Outlook. Whenever an email is moved to that folder you will see the popup.
这篇关于VBA Outlook活动移动电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!