How to Quickly Get the Distance between Two Contacts’ Addresses in Outlook

At times, you may need to count the distance between the specific addresses of two contacts in your Outlook. Instead of checking on internet, here we’ll share another way with you. It permits you to get the distance simply via one click.

Outlook permits users to enter the contact’s address, no matter business address or home address. Sometimes, for some reasons, you may wish to get the distance between two contacts’ addresses. Generally, you could check on Internet. But it is a bit troublesome. Therefore, here we will show you another method, which can let you to get the distance directly inside Outlook without opening browser.

Quickly Get the Distance between Two Contacts' Addresses in Outlook

Get the Distance between Two Contacts’ Addresses

  1. To start with, launch your Outlook application.
  2. Then, after entering the main Outlook window, press “Alt + F11” key buttons.
  3. Subsequently, you’ll get into the “Microsoft Visual Basic for Applications”, in which you need to enable “Microsoft VBScript Regular Expressions”.
  4. Later, open an module that is not being used.
  5. Next, copy the following VBA code into this module.
Sub GetDistanceBetweenTwoContactsAddresses()
    Dim objSelection As Selection
    Dim strFirstAddress As String
    Dim strSecondAddress As String
    Dim objHTTP As Object
    Dim strURL As String
    Dim objRegEx As RegExp
    Dim objMatches As MatchCollection
    Dim strDistance As String
    Set objSelection = Outlook.Application.ActiveExplorer.Selection
    If objSelection.Item(1).Class = olContact And objSelection.Item(2).Class = olContact And objSelection.Count = 2 Then
       If objSelection.Item(1).BusinessAddress <> "" Then
          strFirstAddress = objSelection.Item(1).BusinessAddress
          If objSelection.Item(2).BusinessAddress <> "" Then
             strSecondAddress = objSelection.Item(2).BusinessAddress
             'Search by Google Map
             strURL = "" & Replace(strFirstAddress, " ", "+") & "&destinations=" & Replace(strSecondAddress, " ", "+") & "&mode=car&language=pl&sensor=false"

             Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")

             objHTTP.Open "GET", strURL
             objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0"

             Set objRegExp = New RegExp
             With objRegExp
                  .Pattern = """value"".*?([0-9]+)"
                  .Global = False
             End With
             Set objMatches = objRegExp.Execute(objHTTP.responseText)
             strDistance = objMatches(0).SubMatches(0)
             'Convert meters to miles
             strDistance = Round(strDistance * 0.000621371, 2)
             'Get a message
             MsgBox "There are " & Round(strDistance, 2) & " miles between the two contacts' addresses.", vbInformation + vbOKOnly, "Get Address Distance"
             MsgBox "No Business Address!", vbExclamation + vbOKOnly
         End If
         MsgBox "No Business Address!", vbExclamation + vbOKOnly
      End If
    End If
End Sub

VBA Code - Get the Distance between Two Contacts' Addresses

  1. After that, exit the current window.
  2. Then, for later convenience, you’d better add the new macro to Quick Access Toolbar.
  3. Eventually you can try this macro.
  • To begin with, access “Contacts” area and open a “Contacts” folder.
  • Then, select two contacts that have business addresses.
  • Next, click the macro button in Quick Access Toolbar.
  • Ultimately, you will get a message like the following picture:Message Prompting Distance

What to Do in Case of Outlook Crash

Actually, Outlook crash is almost inevitable most of time. Even so, you still have to make various actions to minimize the corruption from Outlook crashes. First off, it is advisable to make regular and consistent data backups for your Outlook files. In addition, you should keep a remarkable and cogent repair tool in vicinity, such as DataNumen Outlook Repair. It can repair Outlook without any fusses.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including sql corruption and outlook repair software products. For more information visit

Comments are closed.