尝试使用 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