PDA

View Full Version : [VBA] Query an Outlook Distribution List from Excel



sunjinsak
07-19-2016, 08:06 AM
Hi guys,

Note to mods: I've posted this in the Excel section as the code I'm trying to write is to be run from Excel but if you think this should be in the Outlook section instead then please accept my apologies and move it there. Thanks.

Full disclosure: This is a cross-post as I've also posted this same question over at the Mr Excel forums (can't link yet as post count is too low) but no one has replied yet and I need to try to get this done so thought I'd post here as well. I've carried on searching for a solution between posting there and here but still had no joy. If I get an answer over there I'll post it here too and vice-versa so anyone searching for a solution to the same problem can find it easily. Hope this is okay. Anyway, here's my question...

I’m looking for a way to query a specific Outlook distribution list from Excel to see if a member of staff is included on it or not.

I’ve searched quite extensively for a solution and I’ve found plenty of examples of how to extract all the members of a DL, how to count the number of members of a DL or how to add people to a DL etc. but I’ve not found quite what I’m looking for.

I’ve tried to use some of the example code as a base and figure out what I want from there but I’m just not getting it.

Can anyone help?

I was planning on writing a function I could call whenever I need to check. Something along the lines of the following…



Function isMemberOfDL (sPersonToLookUp As String, sDLToQuery As String) As Boolean

‘code to query DL here?
‘isMemberOfDL = True/False based on result of above

End Function


It’s the querying the DL bit I can’t get. I know I’ll need to include a reference to Microsoft Outlook 14.0 Object Library.

I’m using Excel 2013 and Outlook 2010 on Windows 7 Pro.

Thanks in advance for any help or suggestions.