Outlook allows the user to create an object consisting of a group of contacts. This type of object, called a distribution list, has a unique set of features. One of those lets you update contacts that were earlier added to the group list by selecting them in the address book.
Such contacts can evolve, but unfortunately they are not permanently tied with the distribution list. This means that changing contact information and sending a message to a distribution list will not cause the intended effect. Unless the contact was deleted and replaced by an (almost) identical one, it should have a reference number partially consistent with the contact chosen in the list building phase.
e.g. contact has the number: “000000003921EFB12C34994594C86EC4DE706AB084092200”
and based on it, a contact attached to a distribution list has the number:
“00000000C091ADD3519DCF11A4A900AA0047FAA4C3000000003921EFB12C34994594C86EC4DE706AB084092200”
It would seem that, to get the new contact address and replace it simultaneously updating the list member, all one needs to do is refer to the 48 characters of every contact in the list.
Sub contact_data_request() Debug.Print(FindAContact("Surname Name")) Debug.Print(Application.GetNamespace("MAPI").GetItemFromID("000000003921EFB12C34994594C86EC4DE706AB084092200")) End Sub Function FindAContact(ByVal adres As String) As String Dim oItems As Items, oContact As ContactItem Dim oContactFolder As MAPIFolder oContactFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts) oItems = oContactFolder.Items oContact = oItems.Find("[FullName] =" & """" & address & """" & "") FindAContact = oContact.EntryID '.Email1Address 'can be an address oContact = Nothing oContactFolder = Nothing oItems = Nothing End Function
Unfortunately the manufacturer left the parameter oDistList.GetMember(nIndex) .AddressEntry “to be read”. Moreover, the user can change not only the contact address, but also its name. In this case the above code (if working) would return an error. It can be argued that Microsoft left this feature unavailable for the user, because one cannot refer to any of the available parameters of a group member.
Fig.1. Contact list update in Outlook 2007
To get around this problem one can apply automatic clicking method (as by the user).
To achieve this the below provided procedure needs to be embedded in the Outlook developer module [Alt+F11], and then activated from the level of the Outlook contacts folder, where the distribution lists are stored.
Sub distribution_list_update() 'Created by OShon 2011-04-22 VBATools.pl Dim item As Object, oDistList As DistListItem Dim oFolder As MAPIFolder, WshShell, winexist As Boolean oFolder = Application.ActiveExplorer.CurrentFolder For Each item In oFolder.Items DoEvents() If item.Class = 69 Then oDistList = item oDistList.Display() WshShell = CreateObject("WScript.Shell") Do While winexist = False winexist = WshShell.AppActivate(oDistList.DLName) Loop Select Case Val(Application.Version) Case 12 'for Outlook 2007 Sleep(100) : SendKeys("%RU") Sleep(100) : SendKeys("%RSS") Case 14 'for Outlook 2010 Sleep(100) : SendKeys("%TU") Sleep(100) : SendKeys("%TSS") End Select End If Next WshShell = Nothing oDistList = Nothing oFolder = Nothing End Sub
Richard Mueller edited Original. Comment: Removed (en-US) from title, modified title casing, added tags