如何使用 vba 创建规则将已发送的项目移动到文件夹?
How can I use vba to create a rule to move sent items to folder?
在 Outlook(2016 或 365)中,我想使用 VBA 创建一个规则来移动我发送给特定人的项目。
我已经完成了大部分代码(从 Microsoft 代码示例中提取),但我无法弄清楚条件字段应该得到什么。我知道这是不对的(在那种类型的对象中没有“.sender”这样的东西),但我不知道我应该把什么放在那里。 ToOrFromRuleCondition 上只有七个属性(Application、Class、ConditionType、Enabled、Parent、Recipients 和 Session),其中 none 处理发件人。
在下面的代码中:
- colRules、objRuleSend 是 Outlook.Rules 个对象
- objToCondition 是一个 Outlook.ToOrFromRuleCondition
- RuleName 是一个只有字母的字符串
- 地址是具有 name.name@company.com 格式的字符串变量。
Set colRules = Application.Session.DefaultStore.GetRules()
Set objRuleSend = colRules.Create(RuleName & "Send", olRuleSend)
Set objToCondition = objRuleSend.Conditions.SentTo
With objToCondition
.Enabled = True
.Sender = Address ' <-- this is the line that fails.
.Recipients.ResolveAll
End With
您可以拦截Application.ItemSend
事件,检查收件人是否正确,然后将MailItem.SaveSentMessageFolder
属性设置到正确的文件夹。
这应该有效
Set colRules = Application.Session.DefaultStore.GetRules()
Set objRuleSend = colRules.Create(RuleName & "Send", olRuleSend)
Set objToCondition = objRuleSend.Conditions.SentTo
With objToCondition
.Enabled = True
.Recipients.Add Address ' <-- this is the line that is fixed.
.Recipients.ResolveAll
End With
在 Outlook(2016 或 365)中,我想使用 VBA 创建一个规则来移动我发送给特定人的项目。
我已经完成了大部分代码(从 Microsoft 代码示例中提取),但我无法弄清楚条件字段应该得到什么。我知道这是不对的(在那种类型的对象中没有“.sender”这样的东西),但我不知道我应该把什么放在那里。 ToOrFromRuleCondition 上只有七个属性(Application、Class、ConditionType、Enabled、Parent、Recipients 和 Session),其中 none 处理发件人。
在下面的代码中:
- colRules、objRuleSend 是 Outlook.Rules 个对象
- objToCondition 是一个 Outlook.ToOrFromRuleCondition
- RuleName 是一个只有字母的字符串
- 地址是具有 name.name@company.com 格式的字符串变量。
Set colRules = Application.Session.DefaultStore.GetRules()
Set objRuleSend = colRules.Create(RuleName & "Send", olRuleSend)
Set objToCondition = objRuleSend.Conditions.SentTo
With objToCondition
.Enabled = True
.Sender = Address ' <-- this is the line that fails.
.Recipients.ResolveAll
End With
您可以拦截Application.ItemSend
事件,检查收件人是否正确,然后将MailItem.SaveSentMessageFolder
属性设置到正确的文件夹。
这应该有效
Set colRules = Application.Session.DefaultStore.GetRules()
Set objRuleSend = colRules.Create(RuleName & "Send", olRuleSend)
Set objToCondition = objRuleSend.Conditions.SentTo
With objToCondition
.Enabled = True
.Recipients.Add Address ' <-- this is the line that is fixed.
.Recipients.ResolveAll
End With