PC Review


Reply
Thread Tools Rate Thread

Create Outlook Distribution lists in Excel VBA

 
 
christopher.yust@gmail.com
Guest
Posts: n/a
 
      4th Oct 2007
I manage a list of several committees within my group at work and each
group has anywhere from 2 to 40 members. Each person is on 3 to 5
committees. I want to create a macro that can easily create Outlook
distribution lists since people keep joining my group and people can
always change committee preferences.

I have already created a macro that scrolls through the committee
matrix and creates a string for each committee with all the members
included. The string is composed of the names (copied from the
Outlook directory) seperated by a semi-colon (ie. Summer, Kyle; Lindy,
Maria; Sampson, Oscar). This way, I can just copy the cell and
manually create a distribution list in outlook, click on add members,
and all I have to do is paste the list as opposed to individually
adding each member.

I would like to expand it so it actually creates the distribution
lists automatically and either saves them in my Outlook contacts or
saves them to the desktop or my documents so you can simply drag them
into Outlook. That would probably be the easiest way as it would then
prompt you if you want to overwrite existing distribution lists with
the same names.

I've found pieces of code scattered across the internet, but I get
errors when the VBA is simply compiling.

Thanks!!

 
Reply With Quote
 
 
 
 
Steve Yandl
Guest
Posts: n/a
 
      4th Oct 2007
This is an example of a subroutine that looks across row 1 and creates
distribution lists for each of the names found in those cells in the Outlook
Contacts folder. You need to go to 'Tools > References' and set a reference
to the Outlook library for the version of Office you have.

________________________________

Sub MakeOLdistrList()

Dim olApp As Outlook.Application
Dim myDistList As Outlook.DistListItem

Set olApp = New Outlook.Application

colCount = ActiveSheet.UsedRange.Columns.Count

For C = 1 To colCount
Set myDistList = olApp.CreateItem(olDistributionListItem)
With myDistList
.DLName = Cells(1, C).Value
.Save
End With
Next C

Set olApp = Nothing

End Sub

________________________________

Steve



<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I manage a list of several committees within my group at work and each
> group has anywhere from 2 to 40 members. Each person is on 3 to 5
> committees. I want to create a macro that can easily create Outlook
> distribution lists since people keep joining my group and people can
> always change committee preferences.
>
> I have already created a macro that scrolls through the committee
> matrix and creates a string for each committee with all the members
> included. The string is composed of the names (copied from the
> Outlook directory) seperated by a semi-colon (ie. Summer, Kyle; Lindy,
> Maria; Sampson, Oscar). This way, I can just copy the cell and
> manually create a distribution list in outlook, click on add members,
> and all I have to do is paste the list as opposed to individually
> adding each member.
>
> I would like to expand it so it actually creates the distribution
> lists automatically and either saves them in my Outlook contacts or
> saves them to the desktop or my documents so you can simply drag them
> into Outlook. That would probably be the easiest way as it would then
> prompt you if you want to overwrite existing distribution lists with
> the same names.
>
> I've found pieces of code scattered across the internet, but I get
> errors when the VBA is simply compiling.
>
> Thanks!!
>



 
Reply With Quote
 
chrisnyc
Guest
Posts: n/a
 
      8th Oct 2007
Thanks Steve. I'm still having trouble with the Add Member function
of the Distribution list. Here is my code:

TT = ActiveCell.Offset(R, C)

Do While TT <> ""

Do While ActiveCell.Offset(R - 2 - i, C + 1) <> "Grand Total"
'Goes through and pulls all the people that are in a certain
committee
If ActiveCell.Offset(R, C + 1) <> "" And ActiveCell.Offset(R - 2
- i, C + 1) <> "Total" Then
If List <> "" Then
List = List & "; " & ActiveCell.Offset(R - 3 - i,
C + 1)
Else
List = ActiveCell.Offset(R - 3 - i, C + 1)
End If
End If
C = C + 1
Loop

Sheets("Mailing Lists").Activate
Range("A1").Select
ActiveCell.Offset(R, 0) = TT
ActiveCell.Offset(R, 1) = List

Set myDistList = olApp.CreateItem(olDistributionListItem)
With myDistList
.DLName = TT
.AddMember (List)
.Save
End With

List = ""
Sheets("Topic Teams").Activate
Range("A5").Select
R = R + 1
i = i + 1
C = 0
TT = ActiveCell.Offset(R, C)

Loop

Set olApp = Nothing
----------------------------------------

I realize that I may be using Add member incorrectly. However, if I
do this manually, this is what I do. I literally copy what is in the
string "List." I then create a new distribution list in Excel. Name
it. Click on "Select Members" and then paste "List" in the "Members"
field.

Thanks!


On Oct 4, 6:18 pm, "Steve Yandl" <syandl_nos...@comcast.net> wrote:
> This is an example of a subroutine that looks across row 1 and creates
> distribution lists for each of the names found in those cells in the Outlook
> Contacts folder. You need to go to 'Tools > References' and set a reference
> to the Outlook library for the version of Office you have.
>
> ________________________________
>
> Sub MakeOLdistrList()
>
> Dim olApp As Outlook.Application
> Dim myDistList As Outlook.DistListItem
>
> Set olApp = New Outlook.Application
>
> colCount = ActiveSheet.UsedRange.Columns.Count
>
> For C = 1 To colCount
> Set myDistList = olApp.CreateItem(olDistributionListItem)
> With myDistList
> .DLName = Cells(1, C).Value
> .Save
> End With
> Next C
>
> Set olApp = Nothing
>
> End Sub
>
> ________________________________
>
> Steve
>
> <christopher.y...@gmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> >I manage a list of several committees within my group at work and each
> > group has anywhere from 2 to 40 members. Each person is on 3 to 5
> > committees. I want to create a macro that can easily create Outlook
> > distribution lists since people keep joining my group and people can
> > always change committee preferences.

>
> > I have already created a macro that scrolls through the committee
> > matrix and creates a string for each committee with all the members
> > included. The string is composed of the names (copied from the
> > Outlook directory) seperated by a semi-colon (ie. Summer, Kyle; Lindy,
> > Maria; Sampson, Oscar). This way, I can just copy the cell and
> > manually create a distribution list in outlook, click on add members,
> > and all I have to do is paste the list as opposed to individually
> > adding each member.

>
> > I would like to expand it so it actually creates the distribution
> > lists automatically and either saves them in my Outlook contacts or
> > saves them to the desktop or my documents so you can simply drag them
> > into Outlook. That would probably be the easiest way as it would then
> > prompt you if you want to overwrite existing distribution lists with
> > the same names.

>
> > I've found pieces of code scattered across the internet, but I get
> > errors when the VBA is simply compiling.

>
> > Thanks!!- Hide quoted text -

>
> - Show quoted text -



 
Reply With Quote
 
Steve Yandl
Guest
Posts: n/a
 
      8th Oct 2007
Below is the example from VBA help that shows how to add members. I don't
find it intuitive but it is the way it is.

Sub AddNewMembers()
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myDistList As Outlook.DistListItem
Dim myTempItem As Outlook.MailItem
Dim myRecipients As Outlook.Recipients
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myDistList = myOlApp.CreateItem(olDistributionListItem)
Set myTempItem = myOlApp.CreateItem(olMailItem)
Set myRecipients = myTempItem.Recipients
myDistList.DLName = _
InputBox("Enter the name of the new distribution list")
myRecipients.Add myNameSpace.CurrentUser.Name
myRecipients.Add "Dan Wilson"
myRecipients.ResolveAll
myDistList.AddMembers myRecipients
myDistList.Save
myDistList.Display
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
Create Outlook Distribution lists in Excel VBA christopher.yust@gmail.com Microsoft Excel Misc 3 8th Oct 2007 06:51 PM
Create Outlook Distribution lists (default txt file) with excel nicolascap Microsoft Excel Programming 5 3rd Mar 2006 04:36 PM
Outlook should let me create distribution lists from categories =?Utf-8?B?U1BTIFZJUks=?= Microsoft Outlook Contacts 1 9th Mar 2005 10:10 AM
outlook distribution lists in excel carl Microsoft Outlook Discussion 3 16th Sep 2004 09:28 PM
Size Limits of Distribution Lists & How to use existing lists as sources from which to create other lists =?Utf-8?B?aGFiYWRhaTE=?= Microsoft Outlook Discussion 1 27th Apr 2004 04:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:14 AM.