How to Calculate Distances Between Zip Codes in VBA
- 1). Declare variables for the zip codes you want to find the distance between by typing the following code into the top of your VBA program:
Set zip1 = "12345"
Set zip2 = "54321" - 2). Type the following code under your zip code values declaration:
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "http://maps.google.com/maps/nav?output=js&oe=utf8&q=from:" & zip1 & "+to:" & zip2
objHTTP.Open "GET", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send ("") - 3). Press F5 to run your macro and return the distance between the two zip codes.