【发布时间】:2015-08-20 13:47:50
【问题描述】:
我正在尝试在 Outlook 2010 中创建一个非常简单的(因为我是新手并且正在学习)脚本规则。
规则是:如果新邮件来自特定电子邮件地址,请运行我的脚本并停止处理规则。 SCRIPT 检查正文中的字符串。如果找到该字符串,则将电子邮件移至目标文件夹 1,否则将其移至目标文件夹 2。
遗憾的是,我似乎无法让脚本(下面的代码)执行任何操作(邮件只是进入收件箱,而不是脚本中指定的任一文件夹)。其中很多是从在线示例中拼凑而成的,所以我并不完全理解,但我想我现在会在研究我没有得到的东西时问这个问题。有关如何使其按预期工作的任何想法?
'Use the MailItem class of item
Public Sub NCRFRule(Item As Outlook.MailItem)
Dim MAPI As NameSpace 'Don't know what this does
Dim dest1, dest2 As Folder 'declare destination folders
Dim newMail As MailItem 'set item type
'Don't know what this does.
Set MAPI = GetNamespace("MAPI")
'Set the destination folders
Set dest1 = MAPI.Folders("Inbox").Folders("NCRFs")
Set dest2 = MAPI.Folders("Inbox").Folders("other's NCRFs")
'Rule if-statement. If text is found, move mail to dest1 folder
If InStr(1, newMail.Body, "Your Required Action") <> 0 Then
newMail.Move dest1
GoTo cutOut:
End If
'If the above If-statement doesn't execute, text wasn't found,
'move mail to other destination folder.
newMail.Move dest2
cutOut:
End Sub
注意:此代码在“ThisOutlookSession”模块中。
【问题讨论】:
标签: vba email outlook rule inbox