当用户手动将电子邮件移至“存档"文件夹时向用户发出警报 [英] Alert user when the user manually moves an email to an Archive folder
问题描述
我发现自己不小心将电子邮件项目移动到了Microsoft Outlook中的存档"文件夹而不是标准文件夹中.例如,对于Example@Email.Com的电子邮件地址,我打开存档以在文件夹"KeepThis"中找到一个旧的电子邮件,但是随后我忘记了折叠存档文件夹,因此我无意中将其他一些电子邮件稍后移动到了该文件夹中.当我真的想将其保存到Example@Email.Com/KeepThis文件夹时,将其存档/KeepThis文件夹.
I have found myself accidentally moving email items to an Archive folder instead of the standard folder in MS Outlook. For example, for an email address of Example@Email.Com, I open the Archive to locate an old email in folder "KeepThis" but then I forget to collapse the Archive folder and so I inadvertently move some other email message later on into the Archive/KeepThis folder when I really wanted to move it to the Example@Email.Com/KeepThis folder.
当电子邮件项被手动移动到存档"文件夹中时,是否可以使用VBA代码来提醒用户?
I tried unsuccessfully to modify the code by @thims at create-outlook-rule-which-runs-after-move-mail-to-specific-folder to show a msgbox, but could not figure out how to get it to trigger when I moved a mail item to any folder in either my main email folder nor in the Archive.
这是我尝试过的:
(1)我向ThisOutlookSession添加了以下代码(显然是我的实际电子邮件地址):
(1) I added the following code to ThisOutlookSession (obviously with my actual email address):
Public WithEvents FolderItems As Outlook.Items
Private Sub Application_Startup()
Set FolderItems = Session.Folders("Example@Email.Com").Folders("Misc").Items
End Sub
Private Sub FolderItems_ItemAdd(ByVal Item As Object)
MsgBox "ItemAdd event was triggered in folder Misc"
End Sub
如果 可行,我将电子邮件项移至未存档电子邮件帐户的其他"文件夹中.耶.
That works if I move an email item into the "Misc" folder in my non-archived email account. Yay.
但是,我无法弄清楚如何将FolderItems对象设置为在将电子邮件移动到任何文件夹时触发.
But, I cannot figure out how to set the FolderItems object to trigger when an email is moved to any folder.
(2)我可以通过以下方式引用常规存档"文件夹:
(2) I can reference the general Archive folder by using:
Set FolderItems = Session.Folders("Archives").Folders("Misc").Items
但是,仅当我将某些内容移动到存档"中的特定杂项"文件夹并且我想在将电子邮件移至"任何"存档文件夹中时触发事件时才会触发,而不仅仅是杂项" 文件夹.
But, that only triggers if I move something to the specific "Misc" folder in Archives and I want to trigger the event when an email is moved to any Archive folder, not just the "Misc" folder.
我尝试过
Set FolderItems = Session.Folders("Archives").Items
但这是行不通的-没有错误,当我将电子邮件移至任何文件夹时不会触发,也不会在存档"中添加/创建新文件夹时触发;因此,我不确定该代码会触发什么.
but that does not work--there's no error, it just does not trigger when I move an email into any folder, nor does it trigger when a new folder is added/created in Archives; so, I'm not sure what will trigger with that code.
感谢任何能使事情发展的指针!
Thanks for any pointers to get things further along!
推荐答案
感谢@niton-显然我需要有人告诉我这是不可能的! ;)
Thanks @niton--apparently what I needed was for someone to tell me it was not possible! ;)
下面的代码将在文件移动到存档"文件夹时提供警报. (它还会在发生任何其他更改时也发出警报,因此,对于经常故意而不是无意间破坏存档"文件夹的人们来说,这可能会有些烦恼.)
The code below will provide an alert whenever a file is moved to an Archive folder. (It will also provide an alert when any other change occurs too, so, it could get a little annoying for folks who are often messing with the Archive folders intentionally instead of unintentionally.)
我将以下代码添加到ThisOutlookSession模块中,并重新启动Outlook,它对我来说就像一个魅力:
I added the following code to the ThisOutlookSession Module and restarted Outlook and it works like a charm for me:
Public WithEvents myFolders As Outlook.Folders
Private Sub Application_Startup()
Set myNS = Application.GetNamespace("MAPI")
Set myFolders = myNS.Folders("Archives").Folders
End Sub
Private Sub myFolders_FolderChange(ByVal Folder As Outlook.Folder)
'this triggers when a change occurs in the Archives folder (e.g., a new item is moved into or deleted from some folder in the Archive folder [often inadvertently])
MsgBox "You have made a change in the Archives folder."
End Sub
在我使用的最终代码中,msgbox会询问我是否要撤消操作.如果我回答[是],则我使用SendKeys ^ z(ctrl + z)自动执行撤消,但是如果有人可以告诉我如何使用VBA执行撤消命令(例如Application.Undo),我会很乐意.或类似的东西.我无法弄清楚.
In the final code I use, the msgbox will ask if I want to Undo the action. If I answer [Yes] then I use a SendKeys ^z (ctrl+z) to automate the undo, but I would love it if someone could tell me how to execute the Undo command using VBA, e.g., Application.Undo or something like that. I could not figure that out.
感谢@niton将我指向关于Microsoft的此信息描述了如何使用FolderChange事件以及一些我修改了适合自己需求的示例代码.
Thanks to @niton for pointing me to this post on Stackoverflow which had a comment by @Ryan Wildry which led me to this information on Microsoft describing how to use the FolderChange event along with some sample code which I modified to fit my needs.
这篇关于当用户手动将电子邮件移至“存档"文件夹时向用户发出警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!