Solved

Find contacts within Outlook 2010 groups

Posted on 2014-02-28
12
283 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
Comment Utility
Hi, rchambers.

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

Author Comment

by:rchambers
Comment Utility
Contact groups.  I.e. what were distribution lists.
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 76

Expert Comment

by:David Lee
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
Create high volume marketing opportunities using email signatures with these top 10 DOs and DON'Ts of email signature marketing.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
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: …

743 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

14 Experts available now in Live!

Get 1:1 Help Now