All contacts from Contact Folder to BCC by code

  • Thread starter Thread starter Gil Araujo
  • Start date Start date
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.

Best Regards
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
 
Back
Top