MSXML2.XMLHTTP有时会超时

时间:2019-03-27 18:21:01

标签: excel vba msxml2

尝试使用MSXML2.XMLHTTP请求确定服务器上是否存在文件。它在大多数时间都有效,但有时会因“操作超时”而失败。最多出现一次错误情况,然后它恢复正常工作。有什么想法吗?

 Public Function InputFileThere(myUrl As String) As Boolean
 Dim myLine As String
 Dim numTimes As Long
 Dim MyRequest As Object
 Dim urlExists As Boolean
 numTimes = 0
 urlExists = False
 Dim dirName As String
 Dim userName As String
 Dim passWord As String
 userName = “******”
 passWord = “******”
 On Error GoTo errorPart
 startHere:
 Set MyRequest = CreateObject("MSXML2.XMLHTTP")
 MyRequest.Open "HEAD", myUrl, False, userName, passWord
 MyRequest.send
 If MyRequest.StatusText = "OK" Then urlExists = True
 GoTo finHere
 errorPart:
 Set MyRequest = Nothing
 numTimes = numTimes + 1
 myLine = " Right now " & Format(Now(), "hh:mm:ss") & " there was an error , numTimes = " &    CStr(numTimes) & " Err Description = " & Err.Description
Application.StatusBar = myLine
Application.Wait (Now() + TimeValue("00:01:00"))
GoTo startHere
finHere:
InputFileThere = urlExists
Set MyRequest = Nothing
End Function

0 个答案:

没有答案