|
楼主 |
发表于 2011-1-27 14:40
|
显示全部楼层
代码如下
- Option Explicit
- Sub chaxun()
- Dim xmlhttp As Object
- Dim intnum As Integer
- Dim i As Integer
- Dim strdaima As String
- Dim strhaoma As String
- Dim getpage As String
- Dim stra As String
- Dim strb(4) As String
- intnum = Application.WorksheetFunction.CountA([A:A])
- For i = 1 To intnum - 1
- Cells(2, 3).Value = "正在查询第" & i & "张"
- Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
- strdaima = Cells(i + 1, 1).Value
- strhaoma = Cells(i + 1, 2).Value
- xmlhttp.Open "get", "http://www.xm-n-tax.gov.cn/BrowseServlet?szsat.trancode=101007&szsat.errpage=%2Fjsp%2Finternet%2Findex%2FerrPage.jsp&szsat.normalpage=%2Fjsp%2Finternet%2Finforservice%2Fidentifyout.jsp&szsat.fpzw.fplx=&szsat.fpzw.fpdm=" & strdaima & "&szsat.fpzw.fphm=" & strhaoma, False
- xmlhttp.setRequestHeader "Content-Type", "text/html"
- xmlhttp.Send ""
- Do Until xmlhttp.ReadyState = 4
- DoEvents
- Loop
- If xmlhttp.Status = 200 Then
- getpage = xmlhttp.responseText
- stra = Replace(Mid(getpage, InStr(getpage, "纳税人识别号:"), InStr(getpage, "</font></td>") - InStr(getpage, "纳税人识别号:")), "src=" & Chr(34) & "/jsp/internet/images/main_reddian.gif" & Chr(34) & " width=" & Chr(34) & "6" & Chr(34) & " height=" & Chr(34) & "10" & Chr(34) & ">", "[")
- strb(0) = Replace(Split(stra, "[")(0), "</td>", "]")
- strb(1) = Replace(Split(stra, "[")(1), "</td>", "]")
- strb(2) = Replace(Split(stra, "[")(2), "</td>", "]")
- strb(3) = Replace(Split(stra, "[")(3), "</td>", "]")
- strb(4) = Replace(Split(stra, "[")(4), "</td>", "]")
- Cells(i + 1, 4).Value = Trim(Mid(Split(strb(0), "]")(1), InStr(Split(strb(0), "]")(1), ">") + 1, Len(Split(strb(0), "]")(1))))
- Cells(i + 1, 5).Value = Trim(Mid(Split(strb(1), "]")(1), InStr(Split(strb(1), "]")(1), ">") + 1, Len(Split(strb(1), "]")(1))))
- Cells(i + 1, 6).Value = Trim(Mid(Split(strb(2), "]")(1), InStr(Split(strb(2), "]")(1), ">") + 1, Len(Split(strb(2), "]")(1))))
- Cells(i + 1, 7).Value = Trim(Mid(Split(strb(3), "]")(1), InStr(Split(strb(3), "]")(1), ">") + 1, Len(Split(strb(3), "]")(1))))
- Cells(i + 1, 8).Value = Trim(Mid(Split(strb(4), "]")(1), InStr(Split(strb(4), "]")(1), ">") + 1, Len(Split(strb(4), "]")(1))))
- Cells(i + 1, 9).Value = Trim(Mid(Split(strb(4), "]")(3), InStr(Split(strb(4), "]")(3), "0000") + 7, InStr(Split(strb(4), "]")(3), "!") - InStr(Split(strb(4), "]")(3), "0000") - 6))
- Set xmlhttp = Nothing
- getpage = Empty
- Else
- reportErr (xmlhttp.Status)
- End If
- Next i
- Cells(2, 3).Value = "查询完毕!"
- MsgBox "OK"
- Cells(2, 3).Value = "查询状态提示栏"
- End Sub
- Sub reportErr(lStatus As Integer)
- Select Case lStatus
- Case 400
- MsgBox "Bad Request", vbCritical, "连接错误"
- Case 401
- MsgBox "Unauthorized", vbCritical, "连接错误"
- Case 402
- MsgBox "Payment Required", vbCritical, "连接错误"
- Case 403
- MsgBox "Forbidden", vbCritical, "连接错误"
- Case 404
- MsgBox "Not Found", vbCritical, "连接错误"
- Case 407
- MsgBox "Proxy Authentication Required", vbCritical, "连接错误"
- Case 408
- MsgBox "Request Timeout", vbCritical, "连接错误"
- Case 503
- MsgBox "Service Unavailable", vbCritical, "连接错误"
- Case Else
- MsgBox "Can not reach by other reason", vbCritical, "连接错误"
- End Select
- End Sub
复制代码
[ 本帖最后由 xmyjk 于 2011-1-28 10:10 编辑 ] |
|