0

How to GET response using VBA?

This code here does not work. In Debug.Pring() or MsgBox is empty.

TargetURL = snURL + selectedMail
Set HTTPReq = CreateObject("WinHttp.WinHttpRequest.5.1")
HTTPReq.Open "GET", TargetURL, False
HTTPReq.SetCredentials snUser, snPass, 0
HTTPReq.setRequestHeader "Accept", "application/json"

Debug.Print HTTPReq.responseText

I want to get JSON data.

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
TheGreatVY
  • 73
  • 9

1 Answers1

0

Optional libraries (needed, if early binding is used, in general the code will work without them):

enter image description here

Change the companyName variable:

Sub TestMe()

    Dim xmlObject As Object
    Dim companyName As String: companyName = "Google"
    Dim strUrl As String
    strUrl = "http://dev.markitondemand.com/MODApis/Api/v2/Lookup/json?input=" & companyName

    Set xmlObject = CreateObject("MSXML2.XMLHTTP")
        With xmlObject
        .Open "GET", strUrl, False
        .Send
    End With

    Dim response As String
    response = "{""data"":" & xmlObject.ResponseText & "}"
    Debug.Print response

End Sub
Vityata
  • 41,328
  • 7
  • 50
  • 86