Outlook VBA - 使用IF AND功能更改已发送邮件中的类别

时间:2014-02-21 17:34:33

标签: vba outlook-vba outlook-2010

计划:Outlook 2010年 VBA技能:新手

问题:我可以使用IF AND语句来更改类别 如果只选择Item.ToItem.SenderEmailAddress,我可以让它运行,但是我不能让它在AND中运行(我甚至可以使用OR运行它)。我想同时根据电子邮件发件人地址的变化更改我的类别 store @domain = SupCat admin @domain = SupAdmin等

它只会获取与category地址相关联的原始Item.To,它不会更改过去,我有相同的代码,但使用单数Item.To

示例:

'this code does not work, it picks up the example below
If Item.To = "support@domain" And Item.SenderEmailAddress = "store@domain" Then
    Item.Categories = "SupCat"
        strBcc = "bccsup@domain"
            Set objRecip = Item.Recipients.Add(strBcc)
            objRecip.Type = olBCC
                If Not objRecip.Resolve Then
                    strMsg = "Could not resolve the Bcc recipient. " & _
                    "Do you want still to send the message?"
                        res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
                    "Could Not Resolve Bcc Recipient")
                        If res = vbNo Then
                            Cancel = True
                        End If
                End If
End If  

'this code works exactly as written
If Item.To = "support@domain" Then
    Item.Categories = "SupGen"
        strBcc = "bccgen@domain"
            Set objRecip = Item.Recipients.Add(strBcc)
            objRecip.Type = olBCC
                If Not objRecip.Resolve Then
                    strMsg = "Could not resolve the Bcc recipient. " & _
                    "Do you want still to send the message?"
                        res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
                    "Could Not Resolve Bcc Recipient")
                        If res = vbNo Then
                            Cancel = True
                        End If
                End If
End If    

提前谢谢你:)

更新
我已尝试在示例1中使用GoTo NextItem命令(在End If之前和之后),它仍然无法在类别或BCC中获取正确的更改。发生的事情是,当发送电子邮件时,它只会读取第二个选项,即通用类别& BCC。它将无法识别AND命令并根据该命令更改信息。

我刚刚尝试使用item.Sender作为选项,它会获取两个BCC地址,但仍然只给它第二类,而不是第一类。

1 个答案:

答案 0 :(得分:0)

永远不会满足AND条件。在发送邮件之前,您应该发现Item.SenderEmailAddress为空。