If you wish to get the time spent on driving from one contact’s address to another contact’s address, you can refer to this article. We’ll share you an intelligent means which can help you achieve the driving time in a moment.
In my previous article – “How to Quickly Get the Distance between Two Contacts’ Addresses in Outlook”, you can learn how to swiftly get the distance between two addresses via one click. Similar to this, many users long for a solution which can let them quickly get the driving time between two contacts’ addresses. In the followings, we will show you such a way in detail.
Get the Driving Time between Two Contacts’ Addresses
- In the first place, start your Outlook application.
- Then, in the main Outlook window, you ought to press “Alt + F11” keys.
- Subsequently, you will get into the “Microsoft Visual Basic for Applications” window.
- Next, you need to open an unused module.
- Then, copy and paste the following VBA code into this module.
Sub GetDrivingTimebetweenTwoContactsAddresses() 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 strDuration As String Set objSelection = Outlook.Application.ActiveExplorer.Selection On Error Resume Next If objSelection.count = 2 And objSelection.Item(1).Class = olContact And objSelection.Item(2).Class = olContact 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 API strURL = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=" & Replace(strFirstAddress, " ", "+") & "&destinations=" & Replace(strSecondAddress, " ", "+") & "&mode=driving&language=en&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 'Get duration .Pattern = "duration(?:.|\n)*?""value"".*?([0-9]+)" .Global = False End With Set objMatches = objRegExp.Execute(objHTTP.responseText) strDuration = objMatches(0).SubMatches(0) 'Convert second to minute If strDuration > 60 Then strDuration = Round(strDuration / 60, 1) End If 'Prompt you MsgBox strDuration & " min required in driving. ", vbInformation + vbOKOnly, "Get Address Distance" Else MsgBox "No Available Address!", vbExclamation + vbOKOnly End If Else MsgBox "No Available Address!", vbExclamation + vbOKOnly End If End If End Sub
- After that, you can close the current window by hitting the “X” icon in the top right corner.
- Later, you should add the new VBA project to the Quick Access Toolbar, which can be accomplished in the “Outlook Options”.
- Finally, you can have a try.
- First off, select two contacts in the contact list,
- Then, click on the macro button in Quick Access Toolbar.
- If both of them have business addresses filled, you will get a message like the following screenshot. It is prompting the driving time from one contact’s address to another.
Rescue Your Corrupted Outlook Data Files
Outlook’s vulnerability has plagued a great number of regular users for long time. Nevertheless, none can escape from this trouble thoroughly. The unique feasible way is to take adequate precautions. For instance, you have to keep a specialized repair tool in vicinity, such as DataNumen Outlook Repair. It is able to fix Outlook data files, thereby extracting maximum data from the corrupted file.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including mdf repair and outlook repair software products. For more information visit www.datanumen.com