Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

vba - Error from VB excel macro code - msxml3.dll -2146697211 The system cannot locate the resource specified

I am using an MSXML.HTTPRequest object in a VB macro (excel) to communicate with an HTTP server. The problem is that it throws the following error intermittently.

msxml3.dll -2146697211 The system cannot locate the resource specified.

I noticed on my system that this happened when the network was down, but my client has complained of it happening intermittently on his machine. Given that his system has Windows 7 installed and it is working at times, I don't think it is an issue of the correct library not being installed. He has tried it on a few networks, but it still fails.

Function xmlHTTPPost(strURL, strData)
    Dim objHttp

    On Error Resume Next
    xmlHTTPPost = ""
    Set objHttp = CreateObject("Microsoft.XMLHTTP")
    If Err.Number <> 0 Then
        Err.Clear
        Set objHttp = CreateObject("MSXML2.XMLHTTP")
    End If
    If Err.Number <> 0 Then
        MsgBox "Error creating XMLHTTP object"
        Err.Clear
        Exit Function
    End If
    objHttp.Open "GET", strURL, False
    If Err.Number <> 0 Then
        Err.Clear
        Set objHttp = Nothing
        Exit Function
    End If
    objHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    objHttp.setRequestHeader "User-Agent", "Mozilla Compatible (MS IE 3.01 WinNT)"
    objHttp.Send
    If Err.Number <> 0 Then
        MsgBox "Error " & Hex(Err.number) & " sending to server:" & vbCrLf & Err.description
        xmlHTTPPost = "ERROR: " & Err.Source & " " & Err.Number & " " & Err.Description
        Err.Clear
    Else
        xmlHTTPPost = objHttp.responseText
    End If
    Set objHttp = Nothing
End Function

It's working perfectly on my box, which is a Windows 7 + Microsoft Office 2007 installation.

I have searched a lot online, and two reasons have been vaguely mentioned.

  1. Network issues due to proxy or firewall. In this case it should never connect, not intermittently.
  2. Library installation issue. Again, it shouldn't work at all but that's not the case.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For now I was able to solve this by changing the method from GET to POST. The error was intermittent but fortunately it started showing up on my dev machine once, and changing the HTTP method to POST did the trick. It's very odd that should happen though, but it worked.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...