我试图通过VBA创建一个方法,当我使用这个方法时,它会显示#NAME?,有时还会显示#value。
Public Function DISTANCE(start As String, dest As String, key As String)
Dim firstVal As String, secondVal As String, lastVal As String
firstVal = "http://dev.virtualearth.net/REST/V1/Routes/Driving?wp.0="
secondVal = "&wp.1=destinations="
lastVal = "&optimize=time&routePathOutput=Points&distanceUnit=km&output=xml&key=" & key
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 ("")
DISTANCE = Round(Round(WorksheetFunction.FilterXML(objHTTP.ResponseText, "//TravelDistance"), 3) * 1.609, 0)
End Function
1条答案
按热度按时间5vf7fwbs1#
三件事。
1.需要以小写形式传入和传出位置,沿着,表示州的2个字母缩写
1.以上内容需要进行urlencoded
1.响应有一个默认的名称空间,您需要将其添加进去。对于后者,我采用MSXML2.DOMDocument,以便能够添加名称空间。