|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
XMLHttp的方式有问题,要换成WinHttp.WinHttpRequest.5.1
用下面代码可以正常使用:
Sub 里程查询百度版()
k = [a65535].End(xlUp).Row
Application.ScreenUpdating = False
For i = 2 To k
Dim CityFrom As String
Dim CityTo As String
CityFrom = Cells(i, 1)
CityTo = Cells(i, 2)
Dim strText As String
Dim URL As String
Dim dis, mtime, test
Dim strJS As String
With CreateObject("WinHttp.WinHttpRequest.5.1")
URL = "http://map.baidu.com/?"
URL = URL & "newmap=1&reqflag=pcmap&biz=1&qt=nav"
URL = URL & "&c=1"
URL = URL & "&sn=2$$$$$$" & CityFrom & "$$0$$$$"
URL = URL & "&en=2$$$$$$" & CityTo & "$$0$$$$"
.Open "GET", URL, False
.send
'等待响应
Do While .WaitForResponse <> True
DoEvents
Loop
strText = .responseText
dis = Val(Split(strText, """dis"":")(1))
'mtime = Val(Mid(strText, InStrRev(strText, """time"":") + 7))
'MsgBox "约" & Format(dis / 1000, "0.00公里/") & Format(mtime / 86400, "hh小时nn分钟")
Cells(i, 3) = dis / 1000
End With
Next
Application.DisplayStatusBar = True
End Sub
|
|