Excel vba - Httprequest GET

Asked

Viewed 1,097 times

2

I am trying to do a GET in VBA in Excel, and found several examples, below is what I am using:

Sub http()
    Dim MyRequest As Object

    Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
    MyRequest.Open "GET", "http://www.google.com", False

    MyRequest.Send

    MsgBox MyRequest.ResponseText

End Sub

In all examples I have tested, it shows the following error when running MyRequest.Send:

"Runtime error '-2147012889 (80072ee7)':
Server name or address cannot be solved"

Already includes the reference Microsoft WinHTTP Services, version 5.1 in my project.

What may be going on or missing?

EDIT
I also tried to change:

MyRequest.Open "GET", "http://www.google.com", True  

Displays the following error:

"Runtime error '-2147483638 (8000000a)':
The data required to complete this operation is not yet available"

NOTE: The network here in the company is protected by firewall

2 answers

2


I simulated here with your same code and it worked correctly. Even when you change the value of the parameter to true displayed the same error.

For me, the "Server Name or Address cannot be solved" error happens if I purposely type an invalid URL name. With that, I assumed the following:

first Works when searching with other addresses?

If yes, then your DNS is not able to specifically find some addresses. Change the DNS.

2nd If your computer or network is protected by a firewall or proxy, make sure excel is allowed to access the Web.

  • I haven’t tried several different sites and the same mistake. So that must be what you said, because I’m trying to do it in the bank where I work and here it’s full of it... What I do not understand is that I can access these sites, but by the excel of this error.

  • If the problem is the second option, would have some solution?

  • @Thiago I added a manual entry to the firewall and in fact, the error returned was "A connection to the server could not be established" with this, we should also discard the 2nd option. I’ll run another DNS test and get back to you.

  • This does not provide an answer to the question. To criticize or request clarification from an author, leave a comment below its publication. - From Review

  • @Andrefigueiredo did not answer the question why?

-2

The same mistake was made here, too. But when I put the URL with https instead of http, the code worked well!

MyRequest.Open "GET", "https://www.google.com", False

Browser other questions tagged

You are not signed in. Login or sign up in order to post.