WebサーバーからExcelにxmlデータを取得しようとしています。次に、sendRequest
Excelで呼び出す関数を作成しました。
=sendRequest("http://abb.com/index.php?id=111")
Webサーバーに問題がある、接続できない、または見つからない、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: request time-out"
MsgBox ("Server error: request time-out")
End Function
通常、XMLHTTP
のタイムアウトが発生すると、イベントOnTimeOutMessage
が実行されます(参照番号1、#2)。しかし、私のテストのようにOnTimeOutMessage
、の最初に実行されますsendRequest()
Msxml2.ServerXMLHTTP.6.0リクエストがタイムアウトしたときにコールバック関数を使用するにはどうすればよいですか?
お手伝いありがとうございます!