按规则更改类别

问题描述 投票:0回答:1

运行 VBA 代码将电子邮件规则应用到文件夹 (oRule.Execute) 后,在 UI 中我可以看到应用于 TempFolder 中邮件的类别;但是,通过 VBA 检查邮件的

.Categories
时,
.Categories
为空白/vbNullString。

Dim vItem                   As Variant

Dim TempFolder              As Outlook.Folder
Dim oRule                   As Outlook.Rule
Dim oRules                  As Outlook.Rules

Set oRules = Outlook.Application.Session.DefaultStore.GetRules
Set oRule = oRules.Item("RuleName")
 
Set TempFolder = Application.Session.GetDefaultFolder(olFolderDeletedItems).Folders.Add("temporary")

' there is code here to move a copy of a mail item into TempFolder

oRule.Execute Folder:=TempFolder

For Each vItem In TempFolder.Items
    ' vItem.Categories = vbNullString
    debug.print "vItem.Categories = " & vItem.Categories
Next

代码已按预期工作。

我不确定它是如何进入或退出这种行为的。我看到它在删除临时文件夹后进入这种状态。无论 TempFolder 位于何处,都会发生此行为。

vba outlook
1个回答
0
投票

我无法测试它,因为你的示例不是我可以重现的最小示例,但是根据 MS 本身,似乎你需要提交

oRule.Execute Folder:=TempFolder

如果您想一致地应用规则并在当前会话之外保留规则,请使用 Rule.Enabled

,然后使用 Rules.Save。 因此,建议您在需要提供 MCVE 之前,执行以下操作:

oRule.Execute Folder:=TempFolder, ShowProgress:=True '<= just to help debug oRule.Save '<= here For Each vItem In TempFolder.Items ' vItem.Categories = vbNullString debug.print "vItem.Categories = " & vItem.Categories Next
    
© www.soinside.com 2019 - 2024. All rights reserved.