来自网页的消息。堆栈溢出:1

时间:2014-03-24 20:24:47

标签: vba error-handling excel-2010 xmlhttprequest

这是代码,当我在下面描述的行上运行它和F8时,我得到上面的msg。在我离开它之前,必须先单击“确定”按钮17次。仅发生几个网页,其余(1000s)工作正常。在该行之前和之后尝试On Error Resume Next无效。知道代码如何忽略msg并继续吗?

    Dim XMLHTTP As Object
    Dim myURL As String
    Dim html As Object

    With CreateObject("MSXML2.serverXMLHTTP")
    .Open "GET", myURL, False
    .setRequestHeader "Content-Type", "text/xml"
    .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0"
    On Error Resume Next
    .send

    Set html = CreateObject("htmlfile")
    html.body.innerHTML = .ResponseText 'getting the err msg here when I F8 on this line
    End With

1 个答案:

答案 0 :(得分:0)

你试过吗

On Error Resume Err_Label
Dim XMLHTTP As Object
Dim myURL As String
Dim html As Object

With CreateObject("MSXML2.serverXMLHTTP")
.Open "GET", myURL, False
.setRequestHeader "Content-Type", "text/xml"
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0"

.send

Set html = CreateObject("htmlfile")
html.body.innerHTML = .ResponseText 'getting the err msg here when I F8 on this line
End With

Exit sub

err_label:
'any error logging/reporting goes here
 exit sub