Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add BCC to email with VBA in Outlook 2013

Tags:

vba

outlook

I can't figure out the correct VBA code for Outlook 2013 to add a fixed email address to the BCC field of an email while it is open for editing. I have the following code, which creates the email and then sets the BCC.

I want to add BCC to emails that I am replying to, so the message will already be in 'draft' form.

Sub sendcomment_click()
Set oMsg = Application.CreateItem(olMailItem)

With oMsg
    .Recipients.Add ("email address")
    'Set objRecip = Item.Recipients.Add("email address")
    'objRecip.Type = olBCC
    'objRecip.Resolve

    ' Join Email addresses by "; " into ".BCC" as string
    .BCC = "[email protected]; [email protected]"

    .Subject = "New Comment by"
    .Body = "sdfsdfsdf"
    .Display ' Comment this to have it not show up
    '.Send ' Uncomment this to have it sent automatically
End With

Set oMsg = Nothing
End Sub

* Update *

I implemented the great advice from Dmitry

My code now reads:

Sub BCC()
Dim objRecip As Recipient
Set oMsg = Application.ActiveInspector.CurrentItem

With oMsg

Set objRecip = item.Recipients.add("[email protected]")
objRecip.Type = olBCC
objRecip.Resolve

End With

Set oMsg = Nothing

End sub

However, when I try to run it I get an error "Run Time error '424' Object required" and it highlights the line:

Set objRecip = item.Recipients.Add("[email protected]")
like image 312
Alastair Collier Avatar asked Jan 26 '14 15:01

Alastair Collier


People also ask

How do I automatically BCC an email?

Under When emails are sent from, you should see your email address already filled in. In the drop-down menu beneath that, select the to anyone option. In the then automatically drop-down list, select BCC (or CC if you prefer) and enter your email address. Click Save Rule.


2 Answers

Instead of Application.CreateItem(olMailItem), use Application.ActiveInspector.CurrentItem. If you set the BCC property, you will wipe out all existing BCC recipients. Use Recipients.Add (you have it commented out above) for each email address.

like image 59
Dmitry Streblechenko Avatar answered Oct 08 '22 05:10

Dmitry Streblechenko


You need to define Item:

Sub Bcc()
Dim objApp As Outlook.Application
Set objApp = Application
Dim objRecip As Recipient
Dim Item As MailItem
Set Item = objApp.ActiveInspector.CurrentItem
With objMsg
Set objRecip = Item.Recipients.Add("[email protected]")
objRecip.Type = olBCC
objRecip.Resolve
End With
End Sub
like image 1
Mostafa Bedor Avatar answered Oct 08 '22 07:10

Mostafa Bedor