VBA Outlook 事件移动电子邮件 [英] VBA Outlook event moving email

查看:95
本文介绍了VBA Outlook 事件移动电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了一种在 Outlook 中获取移动项目/电子邮件事件的方法.

I search a way to get the event of a moving item/email in outlook.

我们可以使用检查员吗?或者也许有一个事件处理程序,比如 itemsent 或 newmail?

Can we use an Inspector? Or maybe there's an event handler like itemsent or newmail?

谢谢

更多详情:

我有 4 个或更多邮箱.每个都有 X 个文件夹和子文件夹(其中 1 个是具有数百万个文件夹的 livelink 框).有的是普通邮箱,也有拖普通邮件的人.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆