相关疑难解决方法(0)

XMLHTTP onTimeOut时如何进行VBA回调函数?

我正在尝试从webserver获取xml数据到excel,然后我写了一个sendRequest函数来调用excel

=sendRequest("http://abb.com/index.php?id=111")

当网络服务器出现问题,无法连接或无法找到时,excel没有响应,这太可怕了!为了避免它,我认为我们应该设置timeOut.这些是我的功能:

Function sendRequest(Url)
    'Call service
    Set XMLHTTP = CreateObject("Msxml2.ServerXMLHTTP.6.0")

    'Timeout values are in milli-seconds
    lResolve = 10 * 1000
    lConnect = 10 * 1000
    lSend = 10 * 1000
    lReceive = 15 * 1000 'waiting time to receive data from server
    XMLHTTP.setTimeOuts lResolve, lConnect, lSend, lReceive

    XMLHTTP.OnTimeOut = OnTimeOutMessage 'callback function

    XMLHTTP.Open "GET", Url, False

    On Error Resume Next
    XMLHTTP.Send
    On Error GoTo 0

    sendRequest = (XMLHTTP.responseText)
End Function

Private Function OnTimeOutMessage()
    'Application.Caller.Value = "Server error: …
Run Code Online (Sandbox Code Playgroud)

excel vba msxml timeout callback

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

callback ×1

excel ×1

msxml ×1

timeout ×1

vba ×1