Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Dec 2009
    Verona, WI
    Thanked 0 Times in 0 Posts

    Search for addressee in current email

    Some email I get has been sent to a very long list of addressees. I need to determine whether it has been sent to specific people so I can avoid forwarding it to them unnecessarily. After grousing about it for a long while I finally broke down and wrote a macro that makes that process easier. When invoked from an open email, it pops up a dialog box asking me who I am searching for then pops up another one telling me if it found that name in the addressee list. I thought I'd share the code in case anyone else finds it useful.

    Sub SearchForAddressee()
    ' Search the current message for an addressee
    ' January 22, 2013
    ' Jeff Erickson
    Dim strAddressees As String, strAddressees1 As String, strAddressees2 As String, strAddresseesU As String, strFindThis As String
    Dim vCarryOn As Variant, vReturn As Variant, intWhere As Integer
    vCarryOn = False
    ' Figure out if the active window is a list of messages or
    ' one message in its own window
    On Error GoTo QuitIfError    ' But if there's a problem, quit gracefully
    Select Case Application.ActiveWindow.Class
        Case olExplorer
            ' The active window is a list of messages (folder); this means there
            ' might be several selected messages
            MsgBox "This only works for messages that are open - at least for now."
            vCarryOn = False
        Case olInspector
            ' The active window is a message window, meaning there will only
            ' be one selected message (the one in this window)
            strAddressees = "To: " & Application.ActiveInspector.CurrentItem.To
            strAddressees = strAddressees & vbCrLf & "CC: " & Application.ActiveInspector.CurrentItem.CC
            strAddressees = strAddressees & vbCrLf & "BCC: " & Application.ActiveInspector.CurrentItem.BCC
            vCarryOn = True
    End Select
    If vCarryOn Then
        ' Put list in clipboard
        vReturn = ClipboardSetText(strAddressees)
        ' Ask what to search for
        strFindThis = InputBox("Who are you looking for?", "Find Email in addressee list", Default)
        'Cancel if Cancel button clicked
        If strFindThis = "" Then
            MsgBox "Cancelled"
            strFindThis = UCase(strFindThis)
            strAddresseesU = UCase(strAddressees)
            ' Search the string
            intWhere = InStr(strAddresseesU, strFindThis)
            If (intWhere > 0) Then
                strAddressees1 = Mid(strAddressees, 1, intWhere - 1)
                strAddressees2 = Mid(strAddressees, intWhere)
                strAddressees = "******FOUND****** at position " & intWhere & vbCrLf & vbCrLf
                strAddressees = strAddressees & strAddressees1 & vbCrLf & vbCrLf & "*********Here:" & vbCrLf & strAddressees2
                strAddressees = "******NOT FOUND******" & vbCrLf & vbCrLf & strAddressees
            End If
            strAddressees = "Searched for: " & strFindThis & " " & strAddressees & vbCrLf & "Addressees are in the clipboard."
            MsgBox strAddressees
        End If
    End If
    GoTo Cleanup
    QuitIfError:       ' Come here if there was some kind of problem
        MsgBox ("Encountered an error")
        ' I should add something more useful here.
    'Nothing to do
    End Sub

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Platinum Lounger
    Join Date
    Dec 2009
    Thanked 231 Times in 219 Posts
    The downside is if the sender uses Blind Copy.

    cheers, Paul

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts