也许我可以说,有一个类似的帖子在讨论类似的问题开始,但我想用不同的代码比写在其他职位即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)
您的帮助将不胜感激!
从'Marketing'到'Where'?所有的电子邮件或特定的电子邮件? – 0m3r
从市场营销到广告(设置oMoveTarget = oInbox.Folders(“广告”)),并移除除主题中“新”或“有兴趣”之外的所有电子邮件。代码的工作原理是将邮件从“收件箱”移动到“广告” – Nosferatu