PC Review


Reply
Thread Tools Rate Thread

All contacts from Contact Folder to BCC by code

 
 
Gil Araujo
Guest
Posts: n/a
 
      19th Jan 2010
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

 
Reply With Quote
 
 
 
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      19th Jan 2010
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

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Gil Araujo" <(E-Mail Removed)> wrote in message
news:8E08BDA0-671F-418C-A9AF-(E-Mail Removed)...
> 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
>


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PST contacts' folder as main contact folder Paolo Microsoft Outlook Contacts 3 27th Jan 2010 07:26 PM
Import contacts from Vista contact folder to outlook 2003 contacts bikeguy55 Microsoft Outlook Contacts 1 4th Feb 2009 05:51 PM
Add Contact in Business Contacts rather than Contacts folder Carl Adams Microsoft Outlook BCM 0 2nd Apr 2008 05:27 PM
How to Sync Public Folder Contacts with Personal Folder Contact Li =?Utf-8?B?TGFyeg==?= Microsoft Outlook Contacts 0 14th May 2007 07:22 PM
How can I DELETE a CONTACT from the Contacts Folder without an Err =?Utf-8?B?RnJ1c3RyYXRlZCAmIEZ1bWluZyBpbiBGYWlydmll Microsoft Outlook Contacts 1 5th Jul 2005 08:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:50 AM.