

So all we have to do is call the API and parse the response to get weather data for a city. I’ve given my API key here but use your own API key by signing up – Openweathermap API key. Read complete documentation of the API here – Weather API Documentation Imperial units for getting the temperature in Fahrenheit, q parameter for the city name and API key for authentication. VBA supports XML built-in so I used mode=xml to return data in XML format. Look at the URL parameters mode=xml, units=imperial, apikey=YourAPIKey and q=newyork. Try copy pasting this URL into your browser It’s a simple URL which has to be called with few parameters and it returns the weather data in JSON, XML or HTML format. I’m using a free weather API from to fetch the weather data for a city. So I created a very simple weather app in Excel VBA. If InStr(objHTTP.One of our readers posted a question on forum asking how to get weather data using VBA. tRequestHeader "User-Agent", "Mozilla/4.0 (compatible MSIE 6.0 Windows NT 5.0)" URL = firstVal & Replace(start, " ", "+") & secondVal & Replace(dest, " ", "+") & lastVal 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 This post includes information on how to calculate the distance in Excel:
