Outlook Macro – Lookup

How often are you in Outlook and you receive an e-mail from someone and you want to know a little bit more about them. It may be as simple as looking up their phone number so that you can get back to them.

This lookup may be on your own intranet site or using LinkedIn, Facebook or Twiter.

The following Outlook macro will allow you to do this.

This first function will allow you to open Internet Explorer with the URL that you pass to it:

Private Sub NavigateToURL(ByVal argURL As String)
    Const READYSTATE_COMPLETE = 4
    Dim objIE As Object
    Set objIE = CreateObject("InternetExplorer.Application")
    With objIE
        .Visible = True
        .navigate argURL
        Do Until .readystate = READYSTATE_COMPLETE
            DoEvents
        Loop
    End With
    'objIE.Quit
    Set objIE = Nothing
End Sub

https://github.com/RossGoodman/Outlook/blob/master/NavigateToURL

Now we have to find some content to pass to the URL.

Public Sub employeeSearch()
    Dim strEmployeeName As String
    Dim item As Object
    
    strEmployeeName = ""
    If TypeName(Application.ActiveWindow) = "Inspector" Then
        Set item = Application.ActiveWindow.CurrentItem
        If TypeOf item Is Outlook.ContactItem Then
            strEmployeeName = item.FullName
        End If
        If TypeOf item Is Outlook.MailItem Then
            strEmployeeName = item.SenderName
        End If
    End If
    strEmployeeName = InputBox("Enter name", , strEmployeeName)
    If strEmployeeName <> "" Then
        NavigateToURL "http://colleaguedirectory.intranet.group/Pages/PeopleResults.aspx?k=" & strEmployeeName
    End If
End Sub

https://github.com/RossGoodman/Outlook/blob/master/EmployeeSearch

If when you call this macro you have either a contact window or an email open the macro will grab the full name of the contact or the sender name of the email. Irrespective it will then display a prompt window with the obtained username which you can then amend or accept.

Confirming the dialogue will then open the requested search URL with the name appended.

This works best by adding a macro button to the toolbar that calls this function.

NOTE:
I have included the URL for my work’s internal directory, if you want to search some external sites you replace the embedded URL with one of:

http://www.linkedin.com/search/fpsearch?type=people&keywords=
https://www.facebook.com/search/results.php?q=
https://twitter.com/search?q=

 

Leave a Reply