Excel api vba
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP") LastVal = "&mode=car&language=pl&sensor=false&key=YOUR_KEY" Public Function GetDistance(start As String, dest As String)ĭim firstVal As String, secondVal As String, lastVal As String 'Calculate Google Maps distance between two addresses
So I knocked up quickly this VBA Function in Excel which uses Google API distance matrix function to calculate the Google Maps distance.īe sure to first replace YOUR_KEY with your personal API key obtained from here. Go here for more options for configuring the Google Maps Distance Matrix API.Ĭalculate distance between two addresses using Google Maps in Excel Simply type in the From an To addresses, select the transportation mode and hit Build URL!. Want to quickly test the Google API? Below a simple form for building a quick Distance URL. |Seattle&destinations=San+Francisco|Victoria+BC&mode=bicycling&language=en Say we want to get the distance between San Francisco and Victoria BC. The API is configured using GET HTTP Params. Google facilitates Google Maps Distance Matrix API for limited usage. Let’s however focus on getting the distance between two addresses.
Google has a lot of useful API out there and I encourage you to go sometime to the Google API Explorer and have a look at what other information you can easily utilize from Excel or your other applications. To get the COORDINATES of any ADDRESS read this post Using the Google Maps Distance Matrix API
#EXCEL API VBA HOW TO#
This post includes information on how to calculate the distance in Excel: