也許我可以說,有一個類似的帖子在討論類似的問題開始,但我想用不同的代碼比寫在其他職位即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