|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
我也是马甲 发表于 2014-11-24 15:26
再求助一下,假如遇到这样的情况,必须要去点击选择一个终点才有公里数,不然为0,这个应该如何解决?
看了 ...
试试看:- Sub Main()
- Dim CityFrom As String
- Dim CityTo As String
- Dim strText As String
- Dim strURL As String
- Dim lngDis As Long
- Dim lngTime As Long
- Dim strJS As String
-
- CityFrom = "襄阳市"
- CityTo = "十堰市"
-
- With CreateObject("MSXML2.XMLHTTP")
- 100: strURL = "http://map.baidu.com/?"
- strURL = strURL & "qt=nav"
- strURL = strURL & "&c=223"
- strURL = strURL & "&sn=2$$$$$$" & CityFrom & "$$0$$$$"
- strURL = strURL & "&en=2$$$$$$" & CityTo & "$$0$$$$"
-
- .Open "GET", strURL, False
- .Send
- strText = .responsetext
-
- strJS = "var a=" & strText & ";"
- lngDis = JSEval(strJS & "a.content.dis||0;")
-
- If lngDis = 0 Then '如果获取不到距离则取新的城市名
- CityFrom = JSEval(strJS & "a.content[0][0].name;")
- GoTo 100
- End If
-
- lngTime = JSEval(strJS & "a.content.time;")
- strText = "起点: " & CityFrom
- strText = strText & vbCr & "终点: " & CityTo
- strText = strText & vbCr & "方式: 驾车"
- strText = strText & vbCr & "路程: " & Format(lngDis / 1000, "0.00公里")
- strText = strText & vbCr & "时间: " & Format(lngTime / 86400, "hh小时nn分钟")
- MsgBox strText
- End With
- End Sub
- Function JSEval(s As String) As String
- With CreateObject("MSScriptControl.ScriptControl")
- .Language = "javascript"
- JSEval = .Eval(s)
- End With
- End Function
复制代码 |
评分
-
3
查看全部评分
-
|