在将邮件从子文件夹移动到收件箱的同时捕获事件 [英] Capture the event while moving the mail from subfolder to inbox

查看:125
本文介绍了在将邮件从子文件夹移动到收件箱的同时捕获事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当邮件从子文件夹移动到收件箱时,我需要捕获事件

I have the requirement to capture the event when the mail is moved from Subfolder to Inbox

文件夹结构如下

myarchive-mailbox name
Inbox Main folder
  requests Sub folder

myarchive
   Inbox
      requests 

当电子邮件从myarchive邮箱名称的请求子文件夹移动到收件箱时,此邮箱项目

When the email is moved from requests subfolder to Inbox, of myarchive mailbox Name ,this mailbox item should be captured and the event handler should be invoked.

我已经实现了将文件从myarchive收件箱移至请求时捕获事件的代码。

I have already implemented the code for capturing the event when the file is moved from myarchive inbox to requests.The code I have written is as below

Private WithEvents Items As Outlook.Events

Private Sub Application_Startup()

    Dim olApp As Outlook.Application
    Dim objFolder As Outlook.MAPIFolder
    Dim objNs As Outlook.NameSpace

    Set olApp =Outlook.Application
    Set objNS =olApp.GetNamespace("MAPI")
    Set objFolder = objNS.Folders("myarchive")
    Set objFolder=objFolder.Folders("Inbox")
    Set Items=objFolder. Folders("requests").Items 
End Sub

Private Sub Items_ItemsAdd(ByVal item As Object)
  MsgBox "You moved the mail to requests folder"
End Sub


推荐答案

假设您将其移至主要的默认收件箱,然后尝试以下代码

Assuming you are moving it to main Default Inbox, Then try the following code

Dim WithEvents SubFolder As Outlook.Folder
Dim Inbox As Outlook.Folder
Dim olNs As Outlook.NameSpace

Private Sub Application_Startup()
    Set olNs = Application.GetNamespace("MAPI")
    Set SubFolder = olNs.Folders("myarchive").Folders("Inbox").Folders("requests")                                                
    Set Inbox = Application.Session.GetDefaultFolder(olFolderInbox)
End Sub

Private Sub SubFolder_BeforeItemMove(ByVal Item As Object, ByVal MoveTo As MAPIFolder, Cancel As Boolean)
    If MoveTo = Inbox Then
        MsgBox Item.Subject & " was moved to Inbox"
    End If

End Sub

否则更改此行

Set Inbox = Application.Session.GetDefaultFolder(olFolderInbox)

为此

Set Inbox = olNs.Folders("myarchive").Folders("Inbox")

Folder.BeforeItemMove事件

这篇关于在将邮件从子文件夹移动到收件箱的同时捕获事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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