Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

vba - Xmlhttp request is raising an Access Denied error

The following Excel macro, which is making an xmlhttp request to this webpage to retrieve some values at a second stage, has worked normally in VBA until some time ago:

Sub WebReq()

Link = "http://it.finance.yahoo.com/q?s=^FCHI&ql=10" & str(rnd())
Set htm = CreateObject("htmlFile")

Set RequestWeb = CreateObject("msxml2.xmlhttp")
With RequestWeb
    .Open "GET", "" & Link & "", False
    .send
    htm.body.innerhtml = .responsetext
End With

End Sub

Now, instead, at the call of the method:

    .send

of the object msxml2.xmlhttp is raising the following error:

Run-time error '-2147024891 (80070005)'
Access is denied. 

I've been looking on the web but all the similar threads are never answered. Can anyone explain me what this error means, and if there's any way I could fix it or even just work around it?

Note: the random string at the end of the variable 'Link' has been added to force the page reloading, since the script is retrieving real-time values and so it should be loaded every time.

Additional information: while looking for a solution, I'm noticing now that the random part of the link is yielding always the same value even when I end the running and restart again:

Link = http://it.finance.yahoo.com/q?s=^FCHI&ql=10 .7055475

Why is this happening? Shouldn't rnd() yield a new random value between 0 and 1 at every call?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Use

CreateObject("MSXML2.ServerXMLHTTP.6.0") 

The standard request fired from a local machine forbids access to sites that aren't trusted by IE. MSXML2.ServerXMLHTTP.6.0 is the server-side object, that doesn't perform those checks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...