Automatically CC/BCC Outlook Messages

AID: 3517
  • Status: Published

8920 points

  • ByBlueDevilFan
  • TypeTips/Tricks
  • Posted on2010-08-02 at 10:01:54
Awards
  • Community Pick
  • Experts Exchange Approved

Bill is an employee at Acme, Inc (a hypothetical company).  Jane, Bill’s boss, wants to be copied on all Bill’s messages.  Why she wants to be copied is immaterial.  She’s the boss.  Bill is pretty good about remembering to add her to the CC line, but sometimes he forgets.  He forgot to add her to a message today, a really important one that got him in trouble with Jane.  She didn’t know what Bill had said in the message and said some things in a meeting that contradicted what Bill had said.  On returning from the meeting Jane chewed Bill out severely.  Now he’s concerned that Jane might fire him if he ever forgets to copy her on another message.

Maybe you aren’t in Bill’s shoes, but there are a good number of managers who want to be copied on all messages or at least all those for a given subject, project, etc.  Sometimes it’s because the boss is a micromanager.  In other cases it’s because these are hot topic messages and the boss needs to be informed.  It might not even be the boss who wants to be copied.  Maybe you’re a member of a team and copying your team mates is the only way to ensure they are informed.  Whatever the reason, there are clearly some circumstances where copying someone else on all messages or on all messages meeting some criteria is required.  The choice then is to remember to add those folks to the CC/BCC line manually on a per message basis, or to employ automation to do the work for you.  I’d rather automate the process so I don’t HAVE to remember.

If we want to automate this, what are our options?  Outlook has a rules feature.  Can we use it to do this?  The answer is “it depends”.  If you only want to copy (i.e., CC) the message, then the answer is yes.  If you need to blind copy (i.e., BCC) an address, then the answer is no.  How about a third-party solution?  Yes, there are third-party solutions available.  These solutions are called add-ins and there are several of them on the market.  The downside is that they aren’t free.  I don’t believe they are terribly expensive, I’ve never used or purchased one, but there is a cost.  There is a free alternative though and who doesn't like free?  The free solution is to write a script.

Before I talk about the scripted approach I need to say a few more words about why you would consider a scripted approach when Outlook’s built-in rules will get the job done at least for CCing messages.  Rules have limits,  two of them: conditions and size.  A rule is limited to the conditions offered by the rules wizard.  If you need something outside of one of those conditions, then you’re out of luck.  Outlook limits the aggregate size of all rules to 32K (see this Microsoft KB article for details).  It’s impossible to equate 32K to an exact number of rules, but it’s easier than you might think to run afoul of this limit.  In contrast, scripts do not suffer from either of these constraints.  The only constraints on building conditions are the existence of a message property for the condition to work against and your ability to write a conditional statement.  There are no size constraints on scripts.

Outlook’s scripting capabilities give it a lot of power.  It allows you to add functionality to the product with relative ease.  In this case it gives us the ability to copy messages to a boss, teammate, or anyone we choose as they are sent in as little as 8 lines of code.  Of course copying all messages to one address represents the simplest condition.  What about copying messages that meeting a condition or copying to different people based on different conditions?  As you might expect that takes a bit more code.  Not a lot more though.  In the following sections I’ve posted code that handles conditions ranging from very simple (i.e. flatly copy all messages to a given address) to moderately complex (i.e. copy to different persons/groups based on some criteria).

Scenario #1.  CC or BCC all messages to one or more addresses.


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkRecipient As Outlook.Recipient
    If Item.Class = olMail Then
	‘Repeat the next two lines for each address you want to copy to.’
       Set olkRecipient = Item.Recipients.Add("someone@company.com")	   ‘<- Change the address’
olkRecipient.Type = olCC    ‘<- Change olCC to olBCC if you want to use blind copy instead of carbon copy.’
        Item.Save
    End If
End Sub
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:

Select allOpen in new window



Scenario #2.  CC or BCC all messages that have a certain word/phrase in the subject.


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkRecipient As Outlook.Recipient
    If Item.Class = olMail Then
        If InStr(1, Item.Subject, "Keyword/phrase") Then                               '<- Change the keyword/phrase.  This test is case sensitive.'
            'Repeat the next two lines for each address you want to copy to.'
            Set olkRecipient = Item.Recipients.Add("someone@company.com")    '<- Change the address'
            olkRecipient.Type = olCC    '<- Change olCC to olBCC if you want to use blind copy instead of carbon copy.'
            Item.Save
        End If
    End If
End Sub
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window



Scenario #3.  CC or BCC to different addresses based on words/phrases in the subject.


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkRecipient As Outlook.Recipient
    If Item.Class = olMail Then
        If InStr(1, Item.Subject, "First keyword/phrase") Then                        '<- Change the keyword/phrase.  This test is case sensitive.'
            'Repeat the next two lines for each address you want to copy to.'
            Set olkRecipient = Item.Recipients.Add("address1@company.com")    '<- Change the address'
            olkRecipient.Type = olCC    '<- Change olCC to olBCC if you want to use blind copy instead of carbon copy.'
            Item.Save
        End If
        If InStr(1, Item.Subject, "Second keyword/phrase") Then                   '<- Change the keyword/phrase.  This test is case sensitive.'
            'Repeat the next two lines for each address you want to copy to.'
            Set olkRecipient = Item.Recipients.Add("address2@company.com")   '<- Change the address'
            olkRecipient.Type = olCC    '<- Change olCC to olBCC if you want to use blind copy instead of carbon copy.'
            Item.Save
        End If
    End If
End Sub
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:

Select allOpen in new window



Scenario #4.  CC or BCC to different addresses based on a category assigned to the message.


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkRecipient As Outlook.Recipient, arrCats As Variant, varCat As Variant
    If Item.Class = olMail Then
        arrCats = Split(Item.Categories, ",")
        For Each varCat In arrCats
            Select Case varCat
                Case "ProjectX"
                    'Repeat the next two lines for each address you want to copy to.'
                    Set olkRecipient = Item.Recipients.Add("ProjectX@company.com")  '<- Change the address'
                    olkRecipient.Type = olCC    '<- Change olCC to olBCC if you want to use blind copy instead of carbon copy.'
                Case "ProjectY"
                    'Repeat the next two lines for each address you want to copy to.'
                    Set olkRecipient = Item.Recipients.Add("ProjectY@company.com")  '<- Change the address'
                    olkRecipient.Type = olCC    '<- Change olCC to olBCC if you want to use blind copy instead of carbon copy.'
                Case "Reports"
                    'Repeat the next two lines for each address you want to copy to.'
                    Set olkRecipient = Item.Recipients.Add("someone@company.com")  '<- Change the address'
                    olkRecipient.Type = olBCC  '<- Change olCC to olBCC if you want to use blind copy instead of carbon copy.'
            End Select
        Next
        Item.Save
    End If
End Sub
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:

Select allOpen in new window



These four scenarios don’t represent all the possibilities.  There are other conditions you could key on (e.g. who the message is addressed to, words or phrases in the body of the message).  This should be enough to get you started.  If you have a scenario that isn’t covered by the examples, then post a comment with the details and I’ll consider adding it to the article.

Adding the Code to Outlook.


Outlook 2003 and Earlier.
  1.  Start Outlook
  2.  Click Tools > Macro > Visual Basic Editor
  3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
  4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of
  5.  Outlook's VB Editor window
  6.  Edit the code as needed.  I included comment lines wherever something needs to or can change
  7.  Click the diskette icon on the toolbar to save the changes
  8.  Close the VB Editor
  9.  Click Tools > Macro > Security
10.  Set the Security Level to Medium
11.  Close Outlook
12.  Start Outlook
13.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros
       and asking if you want to allow them to run.  Say yes.

Outlook 2007.
  1.  Start Outlook.
  2.  Click Tools > Macro > Visual Basic Editor.
  3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession.
  4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's
       VB Editor window.
  5.  Edit the code as needed.  I included comment lines wherever something needs to or can change.
  6.  Click the diskette icon on the toolbar to save the changes.
  7.  Close the VB Editor.
  8.  Click Tools > Trust Center.
  9.  Click Macro Security.
10.  Set Macro Security to "Warnings for all macros".
11.  Click OK.
12.  Close Outlook.
13.  Start Outlook.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros
       and asking if you want to allow them to run.  Say yes.

Summary.


Whether you're in Bill’s shoes or not I hope you find this article useful.  My goal was to show you a simple way to use Outlook’s automation capabilities to perform a routine task and leave you free to concentrate on other, hopefully more important matters.  Although I cannot honestly claim that I’ve implemented all the principles that David Allen laid out in his book “Getting Things Done”, I do practice his "get it all out of your head" principle whenever possible.  Automating a task, even a simple one like remembering to copy messages to someone else, gives me one less thing to remember.  If you only need to CC an address, the condition you need to apply is a simple one, and you do not already have too many rules, then using the rules wizard is your best bet.  If instead you need to BCC an address, you have complex conditions or the rules wizard doesn’t offer a suitable condition, or you already have a plethora of rules and adding more could push you past the 32K limit, then the solution I’ve presented here is probably for you.

Notes.


  • I've yet to test this in Outlook 2010.  I believe it will work, but until I've tested it I don't want to make an unsupported statement that it will.

  • If you already have an ItemSend subroutine that contains code, then you will have to merge this code with that you already have.  Post a comment to this article or open a new question and reference this article and I'll be glad to help you integrate this code with your code.

Asked On
2010-08-02 at 10:01:54ID3517
Tags

outlook

,

vba

,

carbon copying

,

bcc

,

cc

Topic

Outlook Groupware Software

Views
3389

Comments

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top Outlook Experts

  1. apache09

    663,644

    Sage

    2,168 points yesterday

    Profile
    Rank: Genius
  2. alanhardisty

    170,946

    Guru

    0 points yesterday

    Profile
    Rank: Genius
  3. demazter

    131,854

    Master

    0 points yesterday

    Profile
    Rank: Genius
  4. chris_bottomley

    109,375

    Master

    2,800 points yesterday

    Profile
    Rank: Genius
  5. thinkpads_user

    95,624

    Master

    750 points yesterday

    Profile
    Rank: Genius
  6. Rajkumar-MCITP

    89,780

    Master

    0 points yesterday

    Profile
    Rank: Guru
  7. l33tf0b

    83,091

    Master

    0 points yesterday

    Profile
    Rank: Wizard
  8. BlueDevilFan

    73,191

    Master

    50 points yesterday

    Profile
    Rank: Savant
  9. jjmck

    66,336

    Master

    0 points yesterday

    Profile
    Rank: Genius
  10. Neilsr

    61,466

    Master

    0 points yesterday

    Profile
    Rank: Genius
  11. amitkulshrestha

    61,377

    Master

    0 points yesterday

    Profile
    Rank: Genius
  12. jcimarron

    49,232

    0 points yesterday

    Profile
    Rank: Genius
  13. ve3ofa

    46,002

    0 points yesterday

    Profile
    Rank: Genius
  14. dlmille

    45,200

    0 points yesterday

    Profile
    Rank: Genius
  15. akicute555

    44,979

    10 points yesterday

    Profile
    Rank: Wizard
  16. Anuroopsundd

    44,529

    0 points yesterday

    Profile
    Rank: Sage
  17. HendrikWiese

    40,896

    2,000 points yesterday

    Profile
    Rank: Sage
  18. Exchange_Geek

    37,449

    0 points yesterday

    Profile
    Rank: Sage
  19. jordannet

    36,757

    0 points yesterday

    Profile
    Rank: Wizard
  20. acbrown2010

    34,652

    0 points yesterday

    Profile
    Rank: Genius
  21. diverseit

    34,600

    0 points yesterday

    Profile
    Rank: Guru
  22. WORKS2011

    32,775

    0 points yesterday

    Profile
    Rank: Guru
  23. e_aravind

    31,941

    0 points yesterday

    Profile
    Rank: Genius
  24. JBlond

    31,700

    0 points yesterday

    Profile
    Rank: Sage
  25. limjianan

    30,910

    0 points yesterday

    Profile
    Rank: Genius

Hall Of Fame