Rupert Eghardt
asked on
Outlook Macros (cc address)
Hi Guys,
What is the easiest way in MS Outlook to include a CC e-mail address automatically upon completing a "specific" TO address.
I guess we will have to write a macro for every combination between TO & CC addresses?
What is the easiest way in MS Outlook to include a CC e-mail address automatically upon completing a "specific" TO address.
I guess we will have to write a macro for every combination between TO & CC addresses?
Hi, Rupert.
If by "completing" you mean a solution that automatically inserts a CC as soon as you enter/select and address on the To line, then you'd want to find/build an add-in. Macros aren't going to work and neither will rules. A macro will work if you want to add the CC automatically when the user sends the message. Rules won't work for that either since rules only fire when messages arrive and after they are sent.
The code would look something like this. This code would run each time you send something. It first checks to see if the item is an email. If it is, then it checks each of the message's addressees. If the addressee is on the "To" line, then it checks their name against a list of names you've supplied (i.e. the names in the CASE statement). If it finds a match, then it adds one or more addressees to the CC line. When it's all done checking the addressees, it saves any changes to the message (i.e. the newly added CC addresses) and the message goes on its way. You can add as many checks as you need. The only requirement is that the name you check for must exactly match a name in the list of people on the To line.
If by "completing" you mean a solution that automatically inserts a CC as soon as you enter/select and address on the To line, then you'd want to find/build an add-in. Macros aren't going to work and neither will rules. A macro will work if you want to add the CC automatically when the user sends the message. Rules won't work for that either since rules only fire when messages arrive and after they are sent.
The code would look something like this. This code would run each time you send something. It first checks to see if the item is an email. If it is, then it checks each of the message's addressees. If the addressee is on the "To" line, then it checks their name against a list of names you've supplied (i.e. the names in the CASE statement). If it finds a match, then it adds one or more addressees to the CC line. When it's all done checking the addressees, it saves any changes to the message (i.e. the newly added CC addresses) and the message goes on its way. You can add as many checks as you need. The only requirement is that the name you check for must exactly match a name in the list of people on the To line.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim olkRec As Outlook.Recipient, strCC As String
If Item.Class = olMail Then
For Each olkRec In Item.Recipients
If olkRec.Type = olTo Then
Select Case olkRec.Name
Case "John"
strCC = strCC & "Bill@company.com;"
Case "Sally"
strCC = strCC & "Sam@company.com;Susie@company.com"
End Select
Next
End If
If Len(strCC) > 0 Then
strCC = Left(strCC, Len(strCC) - 1)
Item.CC = strCC
Item.Save
End If
End If
End Sub
ASKER
Thank you BlueDevilFan!
I am sure this will give us what we need.
The only problem that I see is that we have to modify the script with each "condition" being added.
I guess it will complicate things a lot to make it read from a table containing the condition / CC-Result fields?
I am sure this will give us what we need.
The only problem that I see is that we have to modify the script with each "condition" being added.
I guess it will complicate things a lot to make it read from a table containing the condition / CC-Result fields?
No, it wouldn't complicate things a lot to read the condition info from a table. Where do you envision the table being stored and in what format?
ASKER
I followed up with the user and they are happy to insert a fixed list of conditions / CC-results in the script for now.
We don't have to configure a table at this time.
How do I link the script in Outlook to action every time a message is sent?
We don't have to configure a table at this time.
How do I link the script in Outlook to action every time a message is sent?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
gowflow