Microsoft Office Productivity Technology

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)
    Dim objIE As Object
    Set objIE = CreateObject("InternetExplorer.Application")
    With objIE
        .Visible = True
        .navigate argURL
        Do Until .readystate = READYSTATE_COMPLETE
    End With
    Set objIE = Nothing
End Sub

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 "" & strEmployeeName
    End If
End Sub

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.

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:


Leave a Reply

Your email address will not be published. Required fields are marked *