I wish to query a users outlook properties via excel to see if they are a member of a specific distribution list. For example "Team D Supervisors" email distribution list. We have macros that we can get their General home page details from but i can't seem to figure out how to check if a user is a member of a specific list. We have four teams and also visitors known as other. So the ultimate aim is to do an If to query if a specific user is a member of Team A Operators if so return string value of Team A, elseif member of Team B operators return string value of Team B and so on up to Team D and if not a member of any of those then return String value of Other.
Also how is the user identifier for outlook is it their email address or just their login identification? As I will be querying a third person in outlook and not myself logged in.
Any assistance would be most appreciated.
Many thanks
Kind regards
Dave
CodePudding user response:
You can use the GetMemeber
method of the DistLisItem
class from the Outlook object model to get each member of the distribution list. For example, the following code locates every distribution list in the default Contacts
folder and determines whether the list contains the current user:
Sub DisplayYourDLNames()
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.Folder
Dim myDistList As Outlook.DistListItem
Dim myFolderItems As Outlook.Items
Dim x As Integer
Dim y As Integer
Dim iCount As Integer
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myFolderItems = myFolder.Items
iCount = myFolderItems.Count
For x = 1 To iCount
If TypeName(myFolderItems.Item(x)) = "DistListItem" Then
Set myDistList = myFolderItems.Item(x)
For y = 1 To myDistList.MemberCount
If myDistList.GetMember(y).Name = myNameSpace.CurrentUser.Name Then
MsgBox "Your are a member of " & myDistList.DLName
End If
Next y
End If
Next x
End Sub
CodePudding user response:
Use AddressEntry.GetExchangeUser.GetMemberOfList
(returns AddressEntries
collection) - see https://docs.microsoft.com/en-us/office/vba/api/outlook.exchangeuser.getmemberoflist