0

I am trying to call this function which utilizes the Bing Maps API:

                                                   Public Function GetDistance(start As String, dest As String, key As String)

Dim firstVal As String, secondVal As String, lastVal As String

firstVal = "https://dev.virtualearth.net/REST/v1/Routes/DistanceMatrix?origins="
secondVal = "&destinations="
lastVal = "&travelMode=driving&o=xml&key=" & key & "&distanceUnit=mi"

Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")

url = firstVal & start & secondVal & dest & lastVal
objHTTP.Open "GET", url, False
objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.Send ("")
GetDistance = Round(Round(WorksheetFunction.FilterXML(objHTTP.ResponseText, "//TravelDistance"), 3) * 1.609, 0)  End Function

However I get the above mentioned error on this line:

Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")

I tried:

Set objHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")

but it did nothing. I added all the references that are available and I still get the same error. This code works on the video I found it from.

BigBen
  • 46,229
  • 7
  • 24
  • 40

0 Answers0