All contacts from Contact Folder to BCC by code

Status
Not open for further replies.
G

Gil Araujo

Hello

I am a newbie on outlook VBA programing.

So far i was able to create a new macro/code that will create me 2 new

emails, populate Subject and add attachements automaticly.

However now i have a problem in populating the BCC lists.

I send this emails to all the contacts within a 2 especific contact folders.

For example purpuses lets say Contact Folder 1 is Called "Newsletter1" and

Contact folder2 is called "NewsLetter2".

So for the 2 new emails that will pop up when i execute the macro i would

like the macro to add in one all the emails in the contact folder

"Newsletter1" to the bcc field, and the other all the emails in the contact

folder "NewsLetter2" to the bcc folder too.

Is this possible? can anyone give me a little help getting through it plz?

I attached below the code i have written so far, it works perfectly so far

but it would be a time saver if the code could inspect the contact folder and

add automaticly all the emails of the contacts in it.

Gil

Sub NewMail()

Dim objOLApp As Outlook.Application

Dim objOLApp2 As Outlook.Application

Dim MyContacts As Outlook.ContactItem

Dim NewMail As Outlook.MailItem

Dim NewMail2 As Outlook.MailItem

Set objOLApp = New Outlook.Application

Set objOLApp2 = New Outlook.Application

Set NewMail = objOLApp.CreateItem(olMailItem)

Set NewMail2 = objOLApp2.CreateItem(olMailItem)

NewMail.Subject = "Information - " & Date

NewMail.Display

NewMail.Attachments.Add ("\\\server\fax\temp2.xls")

NewMail.Attachments.Add ("\\server\fax\temp.xls")

NewMail2.Subject = "Information 1 - " & Date

NewMail2.Display

NewMail2.Attachments.Add ("\\\server\fax\temp2.xls")

NewMail2.Attachments.Add ("\\server\fax\temp.xls")

End Sub
 
K

Ken Slovak - [MVP - Outlook]

Is this code running in the Outlook VBA project? If so never use New or

CreateObject() to get an Outlook.Application object. Use the intrinisic

Application object, it's trusted.

Where are these contacts folders located in the Outlook folders hierarchy?

Are they under the default Contacts folder?

Sub NewMail()

Dim MyContacts As Outlook.ContactItem

Dim NewMail As Outlook.MailItem

Dim NewMail2 As Outlook.MailItem

Set NewMail = Application.CreateItem(olMailItem)

Set NewMail2 = Application.CreateItem(olMailItem)

NewMail.Subject = "Information - " & Date

NewMail.Display

NewMail.Attachments.Add ("\\\server\fax\temp2.xls")

NewMail.Attachments.Add ("\\server\fax\temp.xls")

NewMail2.Subject = "Information 1 - " & Date

NewMail2.Display

NewMail2.Attachments.Add ("\\\server\fax\temp2.xls")

NewMail2.Attachments.Add ("\\server\fax\temp.xls")

Dim Folder1 As Outlook.MAPIFolder

Set Folder1 =

Application.Session.GetDefaultFolder(olFolderContacts).Folders.Item("Newsletter1")

Dim Folder2 As Outlook.MAPIFolder

Set Folder2 =

Application.Session.GetDefaultFolder(olFolderContacts).Folders.Item("Newsletter2")

Dim colItems As Outlook.Items

Dim oContact As Outlook.ContactItem

Dim oRecip As Outlook.Recipient

Set colItems = Folder1.Items

For Each oContact in colItems

Set oRecip = NewMail1.Recipients.Add(oContact.Email1Address)

oRecip.Type = olBCC

Next

' repeat for Folder2 and NewMail2

End Sub

"Gil Araujo" <GilAraujo> wrote in message

news:8E08BDA0-671F-418C-A9AF-70E102207F5B@microsoft.com...
> Hello
> I am a newbie on outlook VBA programing.
> So far i was able to create a new macro/code that will create me 2 new
> emails, populate Subject and add attachements automaticly.

> However now i have a problem in populating the BCC lists.
> I send this emails to all the contacts within a 2 especific contact
> folders.
> For example purpuses lets say Contact Folder 1 is Called "Newsletter1" and
> Contact folder2 is called "NewsLetter2".

> So for the 2 new emails that will pop up when i execute the macro i would
> like the macro to add in one all the emails in the contact folder
> "Newsletter1" to the bcc field, and the other all the emails in the
> contact
> folder "NewsLetter2" to the bcc folder too.

> Is this possible? can anyone give me a little help getting through it plz?

> I attached below the code i have written so far, it works perfectly so far
> but it would be a time saver if the code could inspect the contact folder
> and
> add automaticly all the emails of the contacts in it.

>

> Gil

> Sub NewMail()
> Dim objOLApp As Outlook.Application
> Dim objOLApp2 As Outlook.Application
> Dim MyContacts As Outlook.ContactItem
> Dim NewMail As Outlook.MailItem
> Dim NewMail2 As Outlook.MailItem

> Set objOLApp = New Outlook.Application
> Set objOLApp2 = New Outlook.Application
> Set NewMail = objOLApp.CreateItem(olMailItem)
> Set NewMail2 = objOLApp2.CreateItem(olMailItem)

> NewMail.Subject = "Information - " & Date
> NewMail.Display
> NewMail.Attachments.Add ("\\\server\fax\temp2.xls")
> NewMail.Attachments.Add ("\\server\fax\temp.xls")

> NewMail2.Subject = "Information 1 - " & Date
> NewMail2.Display
> NewMail2.Attachments.Add ("\\\server\fax\temp2.xls")
> NewMail2.Attachments.Add ("\\server\fax\temp.xls")

> End Sub
>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
C [outlook-users] Public Contact Folder not Listed under contacts tab Using Outlook 3
A New Contact entry (custom form) get saved in a public folder and doesn't appear in Outolook Contacts Outlook VBA and Custom Forms 3
G Populate BCC field with all Contacts within a Contact Folder Outlook VBA and Custom Forms 4
D Advanced e-Mail search on from/to contact group only searches for first 20 contacts in group Using Outlook 0
W Remove specific contacts from contact list Outlook VBA and Custom Forms 3
L Wierd Office 365 Contact unable to edit body of random contacts Using Outlook 5
P How to filter primary contacts in business contact manager BCM (Business Contact Manager) 0
M Mail merge to single contacts + contact groups? Using Outlook 4
Q Custom Contact Form - applied to existing contacts Outlook VBA and Custom Forms 5
yooper46 Removal of iCloud contacts in Outlook contact list Using Outlook 8
M mail merging contacts and contact groups. can code achieve this? Using Outlook 11
J Lost contacts.pst afer sync with iCloud: where has contact.pst disapperaed to? Using Outlook 3
J Linking Contacts to a Message Where the Contact isn't an Addressee Using Outlook 1
J Outlook Contacts: How to filter contact phone numbers from a cti request Using Outlook 1
N Contact Groups - names keep changing from Contacts to AddressBook Using Outlook 5
S change default contact list in Outlook 2010 to "contacts" rather than "global" Exchange Server Administration 1
C BCM contact appears in OL contacts as well BCM (Business Contact Manager) 5
S [outlook-users] Create contact group from other user's contacts Using Outlook 1
W email contacts from external contact database. BCM (Business Contact Manager) 1
J how to configure different contact default form for new contacts Outlook VBA and Custom Forms 1
S How to add icon(or picture) field for each contact in contacts view Outlook VBA and Custom Forms 6
P Outlook calendar and contacts sync problem-outlook disconnects Using Outlook.com accounts in Outlook 2
K Font Sizing in Custom Form Regions for Contacts Outlook VBA and Custom Forms 1
O Outlook - hidden contacts? Using Outlook 2
H Synchronize contacts and calendars across multiple devices Using Outlook 0
S Outlook 2016 Change how Outlook shows me contacts in emails Using Outlook 0
L Favorites for People/Contacts? Using Outlook 1
K can't get custom form to update multiple contacts using VBA Outlook VBA and Custom Forms 3
Horsepower Contacts added from iPhone don't show up in Outlook Using Outlook 2
B oContacts.Items.Restrict Misses Some Contacts Outlook VBA and Custom Forms 3
F Moving Contacts to New Profile Using Outlook 0
V Contacts in O365 have changed?? Using Outlook 20
T Outlook 2010 BCM Migration to Standard Contacts BCM (Business Contact Manager) 0
D Outlook Contacts Notes Field Photos to Smartphone Using Outlook 0
G Add to Outlook Contacts - Point to non-default contacts folder Using Outlook 0
D Is a sub folder under contacts necessary to be able to name an Address Book? Using Outlook 1
L Outlook 2016 Contacts missing in Outlook 365 Using Outlook 1
L icloud contacts sync Using Outlook 4
Fozzie Bear Outlook 2016 Creating a shared local Contacts folder Using Outlook 2
M VbScript for Command Button on Contacts Custom Form Using Outlook 1
J Outlook 2013 Change color of text in data fields of contacts in Outlook 2013? Using Outlook 10
M Changing the preferred order for "Put this entry in" list for adding new contacts to the Address Book Using Outlook 1
GregS Exporting contacts Using Outlook 1
O Synchronising contacts Outlook 365 with Google v.v. Using Outlook 4
J can't sync outlook calendar contacts with iphone ipad Using Outlook 4
M PST import from Outlook 2007 to 2010 - Address Book contacts all in 1 group Using Outlook 4
egarneau Meeting updates with external contacts (GMail) Using Outlook 1
T Outlook Contacts ... Changing Font Size, Style, Bold, etc. Using Outlook 2
D Can Exchange Admin Center create a pst for users email/contacts/calendar? Exchange Server Administration 0
bhamberg Contacts in a category Outlook VBA and Custom Forms 11

Similar threads

Top