Jump to content
groovyPost Forums

Outlook 2010 VBScript to CC or BCC in the inbox that is being sent from


zines
Go to solution Solved by zines,

Recommended Posts

Hello,

I posted my question at the link http://www.groovypost.com/howto/microsoft/how-to-automatically-bcc-in-outlook-2010/ yesterday, but today that link is not working. What I want to do is slightly more complicated than what was posted at the link. Below is my original post.

What I am trying to do is create VBscript to CC or BCC (it doesn’t matter which) in the mailbox that I am sending from. I have a total of 5 mailboxes, including my personal and 4 shared boxes. I don’t want this applied to my personal or 1 of the shared, so I want to specify the mailbox names that it is being sent from. If it is one of the 3 it will place a copy of the email being sent into the inbox of the mailbox being sent from.

I know this can be easily done with creating rules, but we have shared mailboxes and due to how we log in, some people don’t like the rules and they uncheck them, very irritating. Also it appears there is no way to record a macro in Outlook, just create one.

I am trying to do something like this:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)If From = "MailBox1@domain.com" Then    Forward.Recipients.Add "MailBox1@domain.com"End IfIf From = "MailBox2@domain.com" Then    Forward.Recipients.Add "MailBox2@domain.com"End IfIf From = "MailBox3@domain.com" Then    Forward.Recipients.Add "MailBox3@domain.com"End IfEnd Sub

I am not familiar with VBScript in Outlook at all, starting to get familiar with it in Excel though. Can someone please take a look at this and see if you know how to do this?

Thanks,

Chris

Link to comment
Share on other sites

I needed to restructure the code a little bit, the previous code would send it to the last mailbox that was listed when it was initially saved as a draft. I don't understand why since it even showed it didn't equal the last mailbox. I should have known better than to code it like that anyway, sloppy. The code below will work better and has structure to it.

Chris

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)Dim objRecip As RecipientDim strMsg As StringDim res As IntegerDim strBcc As StringOn Error Resume NextIf Item.SendUsingAccount = "mailbox1@domain.com" Then    strBcc = "mailbox1@domain.com"Else    If Item.SendUsingAccount = "mailbox2@domain.com" Then        strBcc = "mailbox2@domain.com"    Else        If Item.SendUsingAccount = "mailbox3@domain.com" Then            strBcc = "mailbox3@domain.com"        End If    End IfEnd IfSet objRecip = Item.Recipients.Add(strBcc)objRecip.Type = olBCCIf Not objRecip.Resolve Then    If res = vbNo Then        Cancel = True    End IfEnd IfSet objRecip = NothingEnd Sub

 

Nice answer I will keep a copy of this to use on some of my Outlook installations.

Link to comment
Share on other sites

  • 3 weeks later...
  • Solution

This will allow you to BCC in whatever mailboxes you specify. Notice the section where it has “If” statements that looks like this:If strEmailAccount = "mailbox1@domain.com" Then strBcc = mailbox1@domain.comThere are 3 of these statements, just change the mailbox addresses to what you need. In my code below I have 3 mailboxes specified. If you only want 2 mailboxes, then delete an “If” statement, else if you want 4 mailboxes then add a statement. You can have as few or as many mailboxes you like. All you need to do is make an equivalent amount of “If” statements for each mailbox that you want to BCC.

This will also work when the email is first saved as draft. A lot of other codes will not work if the email was first opened from a draft, but this will. Please vote this answer up if it helps you.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)Dim objRecip As RecipientDim res As IntegerDim strBcc As StringDim strMailCheck As StringDim strEmailAccount As StringstrMailCheck = "No"If Item.SendUsingAccount Is Nothing Then    strEmailAccount = Item.Parent.ParentElse    strEmailAccount = Item.SendUsingAccountEnd IfIf strEmailAccount = "mailbox1@domain.com" Then    strBcc = "mailbox1@domain.com"    strMailCheck = "Yes"Else   If strEmailAccount = "mailbox2@domain.com" Then        strBcc = "mailbox2@domain.com"        strMailCheck = "Yes"    Else        If strEmailAccount = "mailbox3@domain.com" Then            strBcc = "mailbox3@domain.com"            strMailCheck = "Yes"        End If    End IfEnd IfIf strMailCheck = "Yes" Then    Set objRecip = Item.Recipients.Add(strBcc)    objRecip.Type = olBCC    If Not objRecip.Resolve Then        If res = vbNo Then            Cancel = True        End If    End If    Set objRecip = NothingEnd IfEnd Sub
Link to comment
Share on other sites

  • 3 months later...

This will allow you to BCC in whatever mailboxes you specify. Notice the section where it has “If” statements that looks like this:If strEmailAccount = "mailbox1@domain.com" Then strBcc = mailbox1@domain.comThere are 3 of these statements, just change the mailbox addresses to what you need. In my code below I have 3 mailboxes specified. If you only want 2 mailboxes, then delete an “If” statement, else if you want 4 mailboxes then add a statement. You can have as few or as many mailboxes you like. All you need to do is make an equivalent amount of “If” statements for each mailbox that you want to BCC.

This will also work when the email is first saved as draft. A lot of other codes will not work if the email was first opened from a draft, but this will. Please vote this answer up if it helps you.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)Dim objRecip As RecipientDim res As IntegerDim strBcc As StringDim strMailCheck As StringDim strEmailAccount As StringstrMailCheck = "No"If Item.SendUsingAccount Is Nothing Then    strEmailAccount = Item.Parent.ParentElse    strEmailAccount = Item.SendUsingAccountEnd IfIf strEmailAccount = "mailbox1@domain.com" Then    strBcc = "mailbox1@domain.com"    strMailCheck = "Yes"Else   If strEmailAccount = "mailbox2@domain.com" Then        strBcc = "mailbox2@domain.com"        strMailCheck = "Yes"    Else        If strEmailAccount = "mailbox3@domain.com" Then            strBcc = "mailbox3@domain.com"            strMailCheck = "Yes"        End If    End IfEnd IfIf strMailCheck = "Yes" Then    Set objRecip = Item.Recipients.Add(strBcc)    objRecip.Type = olBCC    If Not objRecip.Resolve Then        If res = vbNo Then            Cancel = True        End If    End If    Set objRecip = NothingEnd IfEnd Sub

 

Great find @zines -- thanks for the follow-up! +1

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By Patty
      How can I automatically receive a BCC of all messages I send in Outlook 10?
    • By DJB
      Just converted all our office computers from various versions of Office to Office 2010. We have noticed that in Outlook 2010 each time you reopen outlook your Inbox Folders are collapsed and you must physically reopen every folder and subfolder. I've done google searches and have not had any luck in correcting. Some have over 100 folders to open each day. Please help.
    • By Jezzer
      The options are gone from the outlook 2010 right click menu and I cant find them in the ribbon interface
    • By Austin
      Jeff writes:

      I have read a few of your articles about scheduling Outlook emails. I have a question about taking this a step further. In our office, we have Outlook 2010.
      Issue – some of the execs have now asked that the subordinates email them a daily plan. Every morning we email our calendars with “limited details” to our bosses. Many of us forget when we come straight into full voicemail boxes and back-to-back meetings. So I have been looking for a way to use a Rule or some other mechanism to do this each weekday automatically.
      I hope you get the idea by now, but… Each morning at a specified time, Outlook will email my daily calendar with limited details to a specified list.
      Of course, we all share calendars with each other. Some of the bosses will take the 2 clicks to check our calendars, but others want it sent as described above.
      Any ideas?
      -Jeff
    • By Heinrich Klinge
      Hello ..... I have Outlook 2003 on my DeskTop which I work from when in my home office --- I have Outlook 2010 on my laptop which of course is my work station when I travel. I also have my account on my Android.My e mail address is from the earthlink.net domain.
      I have my desktop and laptop both set to bring me the the mail from earthlink as I never go to that site at all.I have my desktop set to REMOVE data from server.. and on my laptop I have NO as well as on my cell NO.My challenge is not with my cell, however I would like to maintain all e mails on my laptop and desktop without losing them from either.Is there a way of setting up this? I often am traveling and trying to find an e mail that is on my desktop which causes me headaches..Thanks for any help and I hope I have made myself clear on my issue.Heinrich Klingeheinrichklinge@earthlink.net
  • Who's Online   0 Members, 0 Anonymous, 3 Guests (See full list)

    There are no registered users currently online

×
×
  • Create New...