Solved

Find contacts within Outlook 2010 groups

Posted on 2014-02-28
12
285 Views
Last Modified: 2014-03-05
Hi

I've seen from existing questions that it was not possible to search for contacts within groups at Outlook 2007 or earlier.  Has this been introduced at 2010, or does anyone have a quick script which will help?  It's not in my default contacts folder, it's for the contacts folder of a shared mailbox.

Thanks
0
Comment
Question by:rchambers
  • 6
  • 6
12 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 39899358
Hi, rchambers.

I'm not clear on what you mean by "groups".  Can you explain a bit more?
0
 

Author Comment

by:rchambers
ID: 39899877
Contact groups.  I.e. what were distribution lists.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39900124
Ok.  Are we talking about a personal contact group (i.e. one that you create in Outlook) or a group on an Exchange server (i.e. one that was created by your email admin)?  Also, what do you need to know once a match is found in a group?
0
 

Author Comment

by:rchambers
ID: 39900145
It's a contacts folder belonging to a shared mailbox, full of contact groups that are maintained by users of that folder, not email admins.

I want to be able to find out which groups a particular email address is in, but ideally that would extend to any string (I might know a name but not an email for example).  I then know which groups I have to edit.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39900187
Ok.  This should do it.  The code below will search all the groups in the currently selected folder, the folder must be a contacts folder, for the string you enter.  If it finds that string in any of the groups, then it will display a dialog-box showing the name(s) of the groups it is in.  The search looks at both the name and email address.  Right now the search is case sensitive, but I can change that if necessary.  

Follow these instruction to add the code to Outlook.

1.  Start Outlook
2.  Press ALT+F11 to open the Visual Basic editor
3.  If not already expanded, expand Microsoft Office Outlook Objects
4.  If not already expanded, expand Modules
5.  Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
6.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
7.  Click the diskette icon on the toolbar to save the changes
8.  Close the VB Editor

Sub FindInGroup()
    Const MACRO_NAME = "Find in Group"
    Dim strFin As String, strHit As String, olkFol As Outlook.MAPIFolder, olkItm As Object, olkLst As Outlook.DistListItem, olkRec As Outlook.RECIPIENT
    strFin = InputBox("Enter the string to search for.", MACRO_NAME)
    If strFin <> "" Then
        Set olkFol = Application.ActiveExplorer.CurrentFolder
        If olkFol.DefaultItemType = olContactItem Then
            For Each olkItm In olkFol.Items
                If olkItm.Class = olDistributionList Then
                    Set olkLst = olkItm
                    For intCnt = 1 To olkLst.MemberCount
                        Set olkRec = olkLst.GetMember(intCnt)
                        If (InStr(1, olkRec.Address, strFin) > 0) Or (InStr(1, olkRec.Name, strFin) > 0) Then
                            strHit = strHit & vbCrLf & olkLst.Subject
                            Exit For
                        End If
                    Next
                End If
            Next
            If Len(strHit) > 0 Then
                MsgBox "The following groups contain the string " & strFin & vbCrLf & vbCrLf & strHit, vbInformation + vbOKOnly, MACRO_NAME
            Else
                MsgBox "The string " & strFin & " was not found in any groups in this folder.", vbInformation + vbOKOnly, MACRO_NAME
            End If
        Else
            MsgBox "You must select a folder containing contacts before running this macro.", vbCritical + vbOKOnly, MACRO_NAME
        End If
    Else
        MsgBox "You did not enter anything tos earch for.  Operation cancelled.", vbInformation + vbOKOnly, MACRO_NAME
    End If
End Sub

Open in new window


To use the code

1.  Select a folder containing contacts.
2.  Run the macro.
3.  Enter a name, email address, or portion of either to search for.
0
 

Author Comment

by:rchambers
ID: 39900231
Okay so this gives me a list in a message box of all the groups that have a contact in.  But I then need to look up each one in the Outlook explorer window.  Also the message box size is restricted.

Is it possible to filter the current view by the search result?  Allowing me to click into each one in turn to amend the members?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 76

Expert Comment

by:David Lee
ID: 39900249
Is it possible to filter the current view by the search result?

No, that's not possible. If that were possible, then you'd be able to do this by constructing a search in Outlook.  There'd be no need to use code to do this.

Okay so this gives me a list in a message box of all the groups that have a contact in.  But I then need to look up each one in the Outlook explorer window.  Also the message box size is restricted.

I can present the results in a different way that will allow you to click on the item and open it.  You hadn't mentioned you wanted this capability in your original question, which is why I took the approach I did.
0
 

Author Comment

by:rchambers
ID: 39900259
Hi thanks, no you're right I didn't mention this because the question I was asking was about using search, which would give me the results in the list and thus would have standard item functionality, so I didn't really think about how it would be presented alternatively.

I'm surprised this isn't a standard function, I can't be alone in wanting this.  In fact I've seen reference to it having once been an available feature, I don't know how true that is.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 250 total points
ID: 39900509
I don't remember it being a feature, but then I've never needed to use it and don't remember anyone I know ever needing it either.

I've modified the code to present the results in an Internet Explorer window where each entry is hyperlinked to the list the match was found in.  To use this, replace the earlier version of the code with this version.

If the hyperlinks don't work, that means your computer doesn't have the Outlook protocol handler installed.  You'll need to add it to your computer for the links to function.  This page has all the information about the protocol handler, including links to .reg files for adding it to your computer.  

Sub FindInGroup()
    Const MACRO_NAME = "Find in Group"
    Dim strFin As String, strHit As String, olkFol As Outlook.MAPIFolder, olkItm As Object, olkLst As Outlook.DistListItem, olkRec As Outlook.RECIPIENT, objIE As Object
    strFin = InputBox("Enter the string to search for.", MACRO_NAME)
    If strFin <> "" Then
        Set olkFol = Application.ActiveExplorer.CurrentFolder
        If olkFol.DefaultItemType = olContactItem Then
            For Each olkItm In olkFol.Items
                If olkItm.Class = olDistributionList Then
                    Set olkLst = olkItm
                    For intCnt = 1 To olkLst.MemberCount
                        Set olkRec = olkLst.GetMember(intCnt)
                        If (InStr(1, olkRec.Address, strFin) > 0) Or (InStr(1, olkRec.Name, strFin) > 0) Then
                            strHit = strHit & "<a href=""Outlook:" & olkLst.EntryID & """>" & olkLst.Subject & "</a><br>"
                            Exit For
                        End If
                    Next
                End If
            Next
            If Len(strHit) > 0 Then
                Set objIE = CreateObject("InternetExplorer.Application")
                With objIE
                    .Navigate2 "about:blank"
                    Do Until .readyState = 4
                        DoEvents
                    Loop
                    .document.Body.innerHTML = strHit
                    .Visible = True
                End With
            Else
                MsgBox "The string " & strFin & " was not found in any groups in this folder.", vbInformation + vbOKOnly, MACRO_NAME
            End If
        Else
            MsgBox "You must select a folder containing contacts before running this macro.", vbCritical + vbOKOnly, MACRO_NAME
        End If
    Else
        MsgBox "You did not enter anything tos earch for.  Operation cancelled.", vbInformation + vbOKOnly, MACRO_NAME
    End If
    Set objIE = Nothing
    Set olkRec = Nothing
    Set olkLst = Nothing
    Set olkItm = Nothing
    Set olkFol = Nothing
End Sub

Open in new window

0
 

Author Comment

by:rchambers
ID: 39903050
Hi, my IT dept have sorted the missing protocol handler now and this works a treat - many thanks.

It really ought to be a built-in feature though!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 39903296
You're welcome.

You know, a better solution would be a search and replace.  That would save you from having to open each group and manually make the change.
0
 

Author Comment

by:rchambers
ID: 39905787
Agreed but that's a level of complexity I don't really need.  This is fine, and in fact it's already helped me find groups with email addresses in which I had no idea were related.

Thanks again.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now