Program: Outlook 2010
VBA Skill: Novice
Question: Can I use an IF AND statement to change the Category.
I can get it to run if only Item.To
or Item.SenderEmailAddress
are selected, however I can't get it to run in an AND (I can even get it to run with an OR). I would like to have both as I want to change my category based on the change in email sender address.
store @domain = SupCat admin @domain = SupAdmin etc
It will only pick up the original category
associated with the Item.To
address, it won't change past there, I have the same code but using the singular Item.To
Example:
'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
Thank you in advance :)
Update:
I have tried using the GoTo NextItem
command in example 1 (before & after the End If
) and it still will not pick up the correct change in category or BCC. What is happening is that when the email is made it will only read the 2nd option, the generic category & BCC. It will not recognise the AND
command and change the information based on that.
I have just tried it with item.Sender
as the option and it will pick up both BCC addresses, but still only give it the 2nd category, not the first.
The AND condition is never met. You should find Item.SenderEmailAddress is blank until the mail has been sent.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.