邮件项目的.类别为空,但 UI 显示类别已应用

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

当运行VBA将电子邮件规则应用于文件夹(oRule.Execute)时,我可以在代码执行后直观地看到应用于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.