VBA将已读电子邮件移至特定文件夹 [英] VBA to move read emails to specific folders

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

问题描述

我正在努力寻找对什么是合理的常见问题的明确答案?

I'm struggling to find a definitive answer to what must be a reasonably common problem?

我的老板的收件箱中有团队成员的文件夹,但在将电子邮件从收件箱中读出之前,不希望将电子邮件移到那里.因此,我尝试编写一个遵循以下逻辑步骤的宏:

My boss has folders in their inbox for members of the team, but doesn't want to move the emails there until they have been read out of the inbox. So I am trying to write a macro which follows these logical steps:

For each mailitem in inbox:
    Check if read
      Check sender name
      select case True
        sender name like existing folder name
        move item to corresponding folder name
next mailitem

您能帮我把这些放在一起吗,我宁愿迷失在这一个海上!!

Can you help me put this together, I'm rather lost at sea on this one!!

菲尔

推荐答案

遍历Inbox文件夹中的所有项目不是一个好主意.您需要使用查找/Items类的library/ff869597.aspx"rel =" nofollow noreferrer>限制方法可查找与您的条件相对应的所有项目(读取者和发送者名称).在以下文章中了解有关这些方法的更多信息:

Iterating through all items in the Inbox folder is not a good idea. You need to use the Find/FindNext or Restrict methods of the Items class to find all items that correspond to your conditions (read and sender name). Read more about these methods in the following articles:

  • How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET)
  • How To: Use Restrict method to retrieve Outlook mail items from a folder

然后,您可以使用 Move 方法将Microsoft Outlook项目移动到新文件夹.例如:

Then you can use the Move method of the MailItem class to move a Microsoft Outlook item to a new folder. For example:

Sub MoveItems() 
 Dim myNameSpace As Outlook.NameSpace 
 Dim myInbox As Outlook.Folder 
 Dim myDestFolder As Outlook.Folder 
 Dim myItems As Outlook.Items 
 Dim myItem As Object 

 Set myNameSpace = Application.GetNamespace("MAPI") 
 Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox) 
 Set myItems = myInbox.Items 
 Set myDestFolder = myInbox.Folders("Personal Mail") 
 Set myItem = myItems.Find("[SenderName] = 'Eugene Astafiev'") 
 While TypeName(myItem) <> "Nothing" 
  myItem.Move myDestFolder 
  Set myItem = myItems.FindNext 
 Wend 
End Sub

您可能会找到

You may find the Getting Started with VBA in Outlook 2010 article helpful.

这篇关于VBA将已读电子邮件移至特定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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