我想使用与Outlook VBA Macro中不同的代码将邮件从子文件夹移动到子文件夹
我使用的代码来自https://msdn.microsoft.com/zh-cn/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)
设置您的子文件夹
'Specify target folder for rule move action
Set oInbox = Application.Session.GetDefaultFolder(olFolderInbox).Folders("Marketing")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句