代码之家  ›  专栏  ›  技术社区  ›  RonfromPerth

创建新规则时如何设置messageheader

  •  0
  • RonfromPerth  · 技术社区  · 2 年前

    我正在使用vba代码从输入文件中的文本创建规则。规则中我需要的规则条件之一是检查收到的电子邮件的邮件标题,并根据邮件标题内容将电子邮件移动到特定文件夹。 我试过用这个。文本属性无效。 我在谷歌上搜索了一些问题,想找到一个解决方案,但什么都没找到。 我正在使用vba代码创建300多条规则,其中许多规则需要消息头测试。 任何帮助都将不胜感激 罗恩 编辑:当我给oRule分配一个文本字符串时,我遇到了同样的错误。条件主题此代码中的文本。 编辑:我刚刚意识到我没有提到错误——这是“运行时错误'13'-类型不匹配” 我尝试过在字段中使用String和Variant,得到了相同的消息。

    我的代码如下:

    Dim strMessageHeader作为变体

        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
    
    1 回复  |  直到 2 年前
        1
  •  0
  •   Dmitry Streblechenko    2 年前

    你需要设定 Rule.Conditions.MessageHeader.Text 所有物

        2
  •  0
  •   RonfromPerth    2 年前

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

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