【问题标题】:How can I set MessageHeader when creating a rule?创建规则时如何设置 MessageHeader?
【发布时间】:2022-08-24 15:45:46
【问题描述】:

我从输入文件中的文本创建规则。

规则条件之一是检查收到的电子邮件的邮件头,并根据邮件头内容移动电子邮件。

我尝试了 .TEXT 属性无济于事。
我用谷歌搜索但没有任何结果。

我有超过 300 条规则,其中许多都需要消息头测试。

将文本字符串分配给 oRule.Conditions.Subject.Text 时出现相同的错误。

\"运行时错误 \'13\' - 类型不匹配\"

我为这些字段尝试了 String 和 Variant,我得到了同样的信息。

Dim strMessageHeader As Variant

Do While Not EOF(1)
    Input #1, StrRuleName, strCond, strFrom, strSubject, strSentTo, strMessageHeader, strSendersAddress, strMoveTo, strSetCategory
    \' Create the rule
    Set oRule = colRules.Create(StrRuleName, olRuleReceive)
            
    \' What is the condition?
    Select Case strCond
    Case olConditionFrom            \' 1 - Condition is \"from\"
        Set oFromCondition = oRule.Conditions.From
        With oFromCondition
            .Enabled = True
            .Recipients.Add (strFrom)
            .Recipients.ResolveAll
        End With
    Case olConditionSubject         \' 2 - Condition is text \"in the subject\"
        Set oSubjectCondition = oRule.Conditions.Subject
        With oSubjectCondition
            .Enabled = True
            .Text = strSubject
        End With
    Case olConditionSentTo          \' 12 - Condition is \"sent to a specific email\"
        Set oSentToCond = oRule.Conditions.SentTo
        With oSentToCond
            .Enabled = True
            .Recipients.Add (strSentTo)
        End With
    Case olConditionMessageHeader   \' 15 - Condition is text \"in the message header\"
        Set oMsgHdrCond = oRule.Conditions.MessageHeader
        With oMsgHdrCond
            .Text = strMessageHeader
        End With

    标签: vba outlook rules


    【解决方案1】:

    您需要设置Rule.Conditions.MessageHeader.Text 属性。

    【讨论】:

    • 谢谢德米特里。我按照 Set oMsgHdrCond = oRule.Conditions.MessageHeader With oMsgHdrCond .Text = strMessageHeader End With 但我收到一条错误消息,指示运行时错误 13,类型不匹配
    • strMessageHeader 变量的值和类型是什么?
    【解决方案2】:

    我解决了 - .text 需要使用文本数组而不是文本字符串或变体来分配。 我使用了以下有效的方法:

            Case olConditionMessageHeader   ' 15 - Condition is text "in the message header"
                Set oMsgHdrCond = oRule.Conditions.MessageHeader
                With oMsgHdrCond
                    .Enabled = True
                    .Text = Array(strMessageHeader)
                End With)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多