如何将ItemAdd事件应用于自定义文件夹? Outlook 2010 VBA [英] How to apply ItemAdd event to custom folder? Outlook 2010 VBA

查看:87
本文介绍了如何将ItemAdd事件应用于自定义文件夹? Outlook 2010 VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ItemAdd事件方法来监视何时将新项目添加到收件箱"下的子文件夹中.

I am trying to use ItemAdd event method to monitor when new items were added to my subfolder under Inbox.

我的目录结构是这样的:

My dir structure is like this:

- Inbox 
- - subfolder

当新电子邮件添加到子文件夹时,我想运行代码(原因是我使用了将某些电子邮件重定向到该子文件夹的规则).

I want to run the code when new email is added to a subfolder (the reason is I am using a rule that redirects certain emails to this subfolder).

当前,我正在使用以下方法监视收件箱:

Currently I am monitoring my Inbox using this:

Private Sub Application_Startup()
   Set olInboxItems = Session.GetDefaultFolder(olFolderInbox).items
End Sub

Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
/* Code here */ 
End Sub 

但是当我尝试将其用于子文件夹

but when I try to do it for a subfolder

Set subfolderItems = Session.GetDefaultFolder(olFolderInbox).Folders("subfolder").items 
Private Sub subfolderItems_ItemAdd(ByVal Item As Object) 

它不起作用.为什么?添加新电子邮件时如何捕获?

it doesn't work. Why? How can I capture when new email is added?

推荐答案

因为您没有提及

Private WithEvents olInboxItems As Items

您可能忘记了

Private WithEvents subfolderItems As Items

这篇关于如何将ItemAdd事件应用于自定义文件夹? Outlook 2010 VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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