从一个子文件夹移动特定的电子邮件到另一个子文件夹


-1

也许我可以说,有一个类似的帖子在讨论类似的问题开始,但我想用不同的代码比写在其他职位即Outlook VBA Macro to move mail from subfolder to subfolder

我使用的代码取自msdn网站(https://msdn.microsoft.com/en-us/library/office/ff869653.aspx),我所要做的就是能够从收件箱中的子文件夹移动电子邮件,而不是将收件箱用于其他子文件夹。

比方说,子文件夹的名字,我想搜索邮件来自被称为“营销”

我想修改为如下的代码,

Sub CreateRule() 
Dim colRules As Outlook.Rules 
Dim oRule As Outlook.Rule 
Dim colRuleActions As Outlook.RuleActions 
Dim oMoveRuleAction As Outlook.MoveOrCopyRuleAction 
Dim oFromCondition As Outlook.ToOrFromRuleCondition 
Dim oExceptSubject As Outlook.TextRuleCondition 
Dim oInbox As Outlook.Folder 
Dim oMoveTarget As Outlook.Folder 

'Specify target folder for rule move action 
Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox) 
'Assume that target folder already exists 
Set oMoveTarget = oInbox.Folders("Advertisement") 

'Get Rules from Session.DefaultStore object 
Set colRules = Application.Session.DefaultStore.GetRules() 

'Create the rule by adding a Receive Rule to Rules collection 
Set oRule = colRules.Create("Advert rule", olRuleReceive) 

'Specify the condition in a ToOrFromRuleCondition object 
'Condition is if the message is from "[email protected]" 
Set oFromCondition = oRule.Conditions.From 
With oFromCondition 
    .Enabled = True 
    .Recipients.Add ("[email protected]") 
    .Recipients.ResolveAll 
End With 

'Specify the action in a MoveOrCopyRuleAction object 
'Action is to move the message to the target folder 
Set oMoveRuleAction = oRule.Actions.MoveToFolder 
With oMoveRuleAction 
    .Enabled = True 
    .Folder = oMoveTarget 
End With 

'Specify the exception condition for the subject in a TextRuleCondition object 
'Exception condition is if the subject contains "new" or "interest" 
Set oExceptSubject = _ 
    oRule.Exceptions.Subject 
With oExceptSubject 
    .Enabled = True 
    .Text = Array("new", "interest") 
End With 

'Update the server and display progress dialog 
colRules.Save 
End Sub 

我猜我需要修改这些行,但不知道它是如何在子文件夹而不是收件箱中搜索的。

'Specify target folder for rule move action 
Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox) 

您的帮助将不胜感激!

  0

从'Marketing'到'Where'?所有的电子邮件或特定的电子邮件? 24 6月. 162016-06-24 22:45:23

  0

从市场营销到广告(设置oMoveTarget = oInbox.Folders(“广告”)),并移除除主题中“新”或“有兴趣”之外的所有电子邮件。代码的工作原理是将邮件从“收件箱”移动到“广告” 25 6月. 162016-06-25 00:54:40

0

设置你的子文件夹

'Specify target folder for rule move action 
Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox).Folders("Marketing") 
+1

哦哇...这就像一个魅力... 这正是我想要的!再次谢谢! 27 6月. 162016-06-27 07:57:48


0

的文件夹类提供Folders属性返回Folders集合代表所有包含在指定文件夹中的文件夹。

如果你需要得到一个文件夹命名为“市场营销”,你可以使用下面的代码:

Set oMoveTarget = oInbox.Folders("Marketing") 

在情况下,如果文件夹位于下的树,你将不得不递归调用的文件夹属性,例如,参见How to: Enumerate Folders

最后,您可能会发现Getting Started with VBA in Outlook 2010文章有帮助。

  0

感谢您的信息。看看链接,但我正在寻找的答案是添加以下内容,所以我可以从该子文件夹移动的东西。 27 6月. 162016-06-27 08:01:03