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
 
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
G Apply Custom Contacts form to all existing Contacts Outlook VBA and Custom Forms 1
G Add Map It button to Custom Contacts Form in Outlook Outlook VBA and Custom Forms 1
B Sync Outlook Public Folders to Contacts Using Outlook 2
Kika Melo How to mark as Junk any message not from Contacts (in Outlook.com) Using Outlook 3
G Outlook 365 My iCloud Outlook doesn’t work after reinstalling Microsoft365 on Windows 10 PC – now I get error message on contacts and calendar Using Outlook 1
T How to Export & Import GMAIL Contacts into Outlook 2021 ? Using Outlook 4
L Applying new form to existing contacts -- MessageClass Outlook VBA and Custom Forms 3
Bardiferous Weird Contacts Behavior - Can't find any in any address book, but they're in there Using Outlook 3
S client lost 3K contacts when office 365 for mac account deleted from company exchange server Using Outlook 5
O How to sync (one way) contacts between two Outlook (exchange) accounts? Using Outlook 0
P How to clear out all contacts in iCloud, so I can use iCloud-based sync program Using Outlook 1
R How to prevent corrupted Notes format in Calendar and Contacts Using Outlook 0
K Outlook 365 After migrating to Outlook 365, some contacts display in emails with prefixes Using Outlook 0
kburrows Outlook or Phone Combining Contacts? Using Outlook 0
Witzker Add a text line at the end of the note field in all selected Contacts Outlook VBA and Custom Forms 7
G Add contacts birthday to calendar Using Outlook 4
R How to force Outlook to use plain text in notes for Contacts? Using Outlook 1
S Cannot print Contacts Using Outlook 7
V Backup Calendar, Contacts, Tasks in an POP3 data file Using Outlook 3
J Outlook 365 Outlook 2016/365 Contacts Lose Info when Favorited to the To-Do Bar Using Outlook 2
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

Similar threads

Back
Top