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.
Get the Distance between Two Contacts’ Addresses
- To start with, launch your Outlook application.
- Then, after entering the main Outlook window, press “Alt + F11” key buttons.
- Subsequently, you’ll get into the “Microsoft Visual Basic for Applications”, in which you need to enable “Microsoft VBScript Regular Expressions”.
- Later, open an module that is not being used.
- 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 = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=" & 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" objHTTP.Send 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" Else MsgBox "No Business Address!", vbExclamation + vbOKOnly End If Else MsgBox "No Business Address!", vbExclamation + vbOKOnly End If End If End Sub
- After that, exit the current window.
- Then, for later convenience, you’d better add the new macro to Quick Access Toolbar.
- 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:
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.
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 www.datanumen.com