Consulting

Results 1 to 6 of 6

Thread: Updating Distribution Lists

  1. #1
    VBAX Newbie
    Joined
    Mar 2005
    Posts
    1
    Location

    Updating Distribution Lists

    I'm pretty good with Excel VBA but don't know a lot about Outlook.

    I would like to write a simple search/replace tool which would search through all the Distribution Lists in my Personal Address Book (OL2000), look for a particular name, and either remove the name from the list or change it to another name.

    Anyone have any ideas how I might do this?

    Matthew Evans
    Canada

  2. #2
    Knowledge Base Approver VBAX Expert brettdj's Avatar
    Joined
    May 2004
    Location
    Melbourne
    Posts
    649
    Location
    Hi Matthew,

    Attached are two approaches below for accessing the members of your distributions list from VBA (I've assumed Excel) to help get you started. The first uses the Outlook object, the second uses Microsoft CDO 1.21. They dump the distribution lists into Excel.

    It is possible to remove or add members, see http://msdn.microsoft.com/library/de...hAddMember.asp

    Cheers

    Dave

    [vba]
    Sub ContactItems()
    'Set a ref to the Outlook Object
    Dim objApp As Outlook.Application, objNS As Outlook.Namespace
    Dim objFolder As Outlook.MAPIFolder
    Dim objDistLIst 'As Outlook.DistListItem
    Dim v As Long, i As Long
    Set objApp = CreateObject("Outlook.Application")
    Set objNS = objApp.GetNamespace("MAPI")
    Set objFolder = objNS.GetDefaultFolder(olFolderContacts)

    For Each objDistLIst In objFolder.Items
    'skip contacts
    If TypeName(objDistLIst) = "DistListItem" Then
    v = v + 1
    Cells(1, v) = objDistLIst
    For i = 1 To objDistLIst.MemberCount
    Cells(i + 1, v) = objDistLIst.GetMember(i).AddressEntry
    Next
    End If
    Next

    Set objFolder = Nothing
    Set objApp = Nothing
    End Sub

    Sub Approach2()
    'Set a ref to CDO 1.21
    Dim objSession As MAPI.Session, oAddressList As MAPI.AddressList, oEntry As MAPI.AddressEntry
    Dim i As Long
    Dim Mem As MAPI.AddressEntry
    Set objSession = New MAPI.Session
    With objSession
    .Logon , , False, False
    Set oAddressList = .AddressLists("Contacts")
    On Error Resume Next
    For Each oEntry In oAddressList.AddressEntries
    If oEntry.DisplayType = olPrivateDistList Then
    v = v + 1
    i = 1
    Cells(i, v * 2 - 1) = oEntry.Name & " contact"
    Cells(i, v * 2) = oEntry.Name & " address"
    For Each Mem In oEntry.Members
    i = i + 1
    Cells(i, v * 2 - 1) = Mem.Name
    Cells(i, v * 2) = Mem.Address
    Next
    End If
    Next
    End With
    Set oAddressList = Nothing
    Set objSession = Nothing
    End Sub
    [/vba]

  3. #3
    VBAX Contributor
    Joined
    Oct 2004
    Posts
    159
    Location
    With refer to approach 1

    There is a pop up window as attached (Window 2000 + Outlook 2003). How to reply automatically?

    Thanks
    Emily

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Emily,

    Since Office 2000 (I think SP3) there is a new Security feature in Office that makes it nearly impossible for VBA programs to send mail or adjust user enviroment of Outlook without you getting this message.

    The easy way to get rid is by Installing the program ClickYes witch will press the buttons for you.

    All the alternatives are listed here:http://www.outlookcode.com/d/sec.htm

    Enjoy!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  5. #5
    VBAX Contributor
    Joined
    Oct 2004
    Posts
    159
    Location
    Thanks

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    You're Welcome!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •