Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Lounger
    Join Date
    Mar 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Search Distribution Lists (Outlook 2000)

    I think this may have been asked before, but I couldn't find an answer.
    Is there some way of searching a number of distribution lists to find each instance of an email address? I realise that removing the name from the main list of contacts and then updating the list should work, but many of my DLs are old and the names have frequently been added to the list directly.
    Thanks

    SteveCS

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Search Distribution Lists (Outlook 2000)

    If you want to remove a specific e-mail address from all distribution lists, you can use the following macro:

    Sub RemoveFromDistList()
    Dim strAddress As String
    Dim itm As Object
    Dim i As Long
    Dim blnChanged As Boolean

    On Error GoTo ErrHandler

    strAddress = InputBox("Enter e-mail address to remove from distribution lists.")
    If strAddress = "" Then
    Exit Sub
    End If
    strAddress = LCase(strAddress)

    For Each itm In Session.GetDefaultFolder(olFolderContacts).Items
    If itm.Class = olDistributionList Then
    blnChanged = False
    For i = itm.MemberCount To 1 Step -1
    If LCase(itm.GetMember(i).Address) = strAddress Then
    itm.RemoveMember itm.GetMember(i)
    blnChanged = True
    End If
    Next i
    If blnChanged Then
    itm.Save
    End If
    End If
    Next itm

    ExitHandler:
    Set itm = Nothing
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

    Notes:
    - Nothing happens if you provide an invalid e-mail address.
    - This version doesn't ask for confirmation, you can add that if you wish.
    - The code is based on an example by <!profile=JohnBF>JohnBF<!/profile>.

  3. #3
    New Lounger
    Join Date
    Mar 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search Distribution Lists (Outlook 2000)

    Thanks for that Hans, but I am having trouble with it.
    It asks for the email address, but does not remove it from the DL when I look at it again. Should I have modified your code in some way?
    Also, you mentioned getting confirmation. How would I go about that?

    Thanks,
    SteveCS

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Search Distribution Lists (Outlook 2000)

    Hmm, it worked in a small-scale test. The code looks for the exact e-mail address, e.g. billg@microsoft.com.

    Would you like to be asked to confirme deleting from each individual distribution list? If so:

    Sub RemoveFromDistList()
    Dim strAddress As String
    Dim itm As Object
    Dim i As Long
    Dim blnChanged As Boolean

    On Error GoTo ErrHandler

    strAddress = InputBox("Enter e-mail address to remove from distribution lists.")
    If strAddress = "" Then
    Exit Sub
    End If
    strAddress = LCase(strAddress)

    For Each itm In Session.GetDefaultFolder(olFolderContacts).Items
    If itm.Class = olDistributionList Then
    blnChanged = False
    For i = itm.MemberCount To 1 Step -1
    If LCase(itm.GetMember(i).Address) = strAddress Then
    If MsgBox("Delete " & strAddress & " from " & itm.DLName & "?", _
    vbYesNo + vbQuestion) = vbYes Then
    itm.RemoveMember itm.GetMember(i)
    blnChanged = True
    End If
    End If
    Next i
    If blnChanged Then
    itm.Save
    End If
    End If
    Next itm

    ExitHandler:
    Set itm = Nothing
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

  5. #5
    New Lounger
    Join Date
    Mar 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search Distribution Lists (Outlook 2000)

    Hi Hans,
    I think I must be doing something wrong. It still doesn't work. I will keep playing with it, though, in the hopes I can sort it out.

    Thanks again

    SteveCS

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Search Distribution Lists (Outlook 2000)

    I'm using Outlook 2003 at the monent and the code works well there (I tested it again). Perhaps someone else with Outlook 2000 can test it.

  7. #7
    New Lounger
    Join Date
    Mar 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search Distribution Lists (Outlook 2000)

    I had my DLs in a sub-folder of Contacts, and I have now moved them into the Contacts folder. It now works, up to a point. After I allow it access and give the email address, I get an error message "Object does not support this property or method" .

    Any ideas?

    SteveCS

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Search Distribution Lists (Outlook 2000)

    Temporarily comment out the line

    On Error GoTo ErrHandler

    by inserting an apostrophe ' in front of it. When you run the code, you'll get a dialog box offering the options End, Debug and Help. Click Debug. You'll be taken to the Visual Basic Editor and a line will be highlighted in yellow. Which line is that?
    (You can stop macro execution by clicking the "Stop" button on the toolbar.)

  9. #9
    New Lounger
    Join Date
    Mar 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search Distribution Lists (Outlook 2000)

    I did that, but nothing happened. When I went into Visual Basic Editor and hit Debug, it initially highlighted Sub RemoveFromDistList(). When I went to Continue, it asked for the name and then asked for confiormation. I then got an error message "Run Time Error 438. Object does not support this property or method"

    SteveCS

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Search Distribution Lists (Outlook 2000)

    If you really commented out the line

    On Error GoTo ErrHandler

    a line *must* be highlighted when you get the error.

  11. #11
    New Lounger
    Join Date
    Mar 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search Distribution Lists (Outlook 2000)

    Sorry, Hans. I "did" REM the line you suggested, but I still get the error message, not the End, Debug, Help message box.

    Best wishes,

    SteveCS

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Search Distribution Lists (Outlook 2000)

    Sorry, I have no idea what causes this.
    Try the following:
    - Activate the Visual Basic Editor.
    - Position the insertion point anywhere in the macro.
    - Press F8 to enter single-step mode.
    - Each time you press F8, you will execute one step.
    - Keep on pressing F8 until the error occurs. If you have many contacts and distribution lists, this will be *very* tedious, but I don't know a better way.
    - Note where the error occurred.

  13. #13
    New Lounger
    Join Date
    Mar 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search Distribution Lists (Outlook 2000)

    It doesn't highlight it, but it stops at :- itm.RemoveMember itm.GetMember(i)
    StevCS

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Search Distribution Lists (Outlook 2000)

    Thanks, that is helpful. A little searching turned up that RemoveMember was introduced in Outlook 2002 (XP). Since you're using Outlook 2000, it is not available. There is a RemoveMembers method, but it doesn't work dependably (it only removes items that are already in your contacts, not items added directly).

    I'm out of ideas, sorry.

  15. #15
    New Lounger
    Join Date
    Mar 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search Distribution Lists (Outlook 2000)

    Hans,
    Thanks for all your help with this. I will just have to go back to doing it manually.

    SteveCS

Page 1 of 2 12 LastLast

Posting Permissions

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