计划:Outlook 2010年 VBA技能:新手
问题:我可以使用IF AND语句来更改类别
如果只选择Item.To
或Item.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地址,但仍然只给它第二类,而不是第一类。
答案 0 :(得分:0)
永远不会满足AND条件。在发送邮件之前,您应该发现Item.SenderEmailAddress为空。