|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub kuaidi()
- Dim xmlhttp As Object, str1$, str2$, str3$, str4$, arr
- Dim i%, j%
- On Error Resume Next
- lstro = Cells(Rows.Count, 2).End(xlUp).Row
- s = Application.InputBox("请你输入你想查询的开始行号" & Chr(13) & Chr(13) & "查询前请先保存订单表,防止出现未响应而意外关闭未保存" & Chr(13) & Chr(13) & "为避免快递100查询限制,每次查询不要超过100个,2小时内不能频繁查询", "输入开始行号", 2, Type:=1)
- If s = False Then Exit Sub
- If s > lstro Then MsgBox "开始行号不能大于表格中已使用的总行数!": Exit Sub
- t = Application.InputBox("请你输入你想查询的结束行号" & Chr(13) & Chr(13) & "为避免快递100查询限制,每次查询不要超过100个,2小时内不能频繁查询", "输入结束行号", lstro, Type:=1)
- If t = False Then Exit Sub
- If t < s Then MsgBox "结束行号不能小行开始行号!": Exit Sub
- Application.ScreenUpdating = False
- Application.EnableEvents = False
- Set xmlhttp = CreateObject("WinHttp.WinHttpRequest.5.1")
- With xmlhttp
- For j = s To t
- If Cells(j, 2) <> "" And Cells(j, 3) <> "已签收" Then
- .Open "POST", "http://www.kuaidi100.com/autonumber/autoComNum?text=" & Trim(Cells(j, 2).Value)
- .send 'post请求,目的是获得快递公司名称
- str1 = Split(Split(.responsetext, "comCode"":""")(2), """")(0)
- .Open "GET", "http://api.kuaidi100.com/api?id=29833628d495d7a5&com=" & str1 & "&nu=" & Trim(Cells(j, 2).Value)
- .setrequestheader "X-Requested-With", "XMLHttpRequest"
- .setrequestheader "Referer", "http://www.kuaidi100.com/"
- .send
- str2 = .responsetext '取得物流数据
- arr = Split(str2, "{""time"":""")
- Cells(j, 3) = arr(1)
- ' str3 = Split(Split(str2, "{""time"":""")(2), """,""context"":""")(0) & " " & Split(Split(str2, """context"":""")(2), """,""ftime"":""")(0)
- ' str4 = Split(Split(str2, "{""time"":""")(1), """,""context"":""")(0) & " " & Split(Split(str2, """context"":""")(1), """,""ftime"":""")(0)
- '
- '
- ' If InStr(str4, "签收") Then
- ' Cells(j, 3) = "已签收"
- ' Cells(j, 4) = Left(str4, 20)
- ' ElseIf InStr(str2, "已收") And InStr(str2, "派件") = 0 Then Cells(j, 3) = "在途中"
- ' ElseIf InStr(str2, "已揽收") And InStr(str2, "派件") = 0 Then Cells(j, 3) = "在途中"
- ' ElseIf InStr(str2, "揽件") And InStr(str2, "派件") = 0 Then Cells(j, 3) = "在途中"
- ' ElseIf InStr(str2, "派件") Then Cells(j, 3) = "派送中"
- ' ElseIf InStr(str2, "参数异常") Then Cells(j, 3) = "暂无记录"
- ' End If
- End If
- Next
- End With
- Columns("C:D").AutoFit
- Range("C2:D" & t).HorizontalAlignment = xlLeft
- Range("D:D").NumberFormatLocal = "yyyy-m-d"
- Application.ScreenUpdating = True
- Application.EnableEvents = True
- End Sub
复制代码
|
|