Hi i have a Json response at a webpage that i am trying to capture update the existing spreadsheet with that data. I have referenced using the following VBScript. I am getting a blank excel and somehow the spreadsheet is not receiving the json data
JSON Response at the webpage
[
{
"Sno ": "1",
"Name": "Alex",
"Age ": "27",
"City": "Newyork"
},
{
"Sno ": "2",
"Name": "Smith",
"Age ": "25",
"City": "Los angeles"
},
{
"Sno ": "3",
"Name": "austin",
"Age ": "26",
"City": "Calfornia"
}
]
VBScript being used (referrenced it from stack source link)
Sub Button4_Click()
'clearing the contents of the sheet prior to synchronisation of data with GCP
Dim str As String
Dim myarray() As Variant
'Delete existing data
Sheets("Backup_sheet").Activate 'Name of sheet the data will be downloaded into. Change as required.
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Url = "http://127.0.0.1:5555/refresh"
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open "GET", Url, False, "john", "hello"
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.setRequestHeader "Content-Type", "application/json"
QueryQuote:
With Sheets("Backup_sheet").QueryTables.Add(Connection:="Url;" & str, Destination:=Sheets("Backup_sheet").Range("a1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
End With
Sheets("Backup_sheet").Range("a1").CurrentRegion.TextToColumns Destination:=Sheets("Backup_sheet").Range("a1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, other:=True, OtherChar:=",", FieldInfo:=Array(1, 2)
Sheets("Backup_sheet").Columns("A:B").ColumnWidth = 12
Range("A1").Select
End Sub
Expected output post fetching data
Can someone help where i am getting it wrong/ any suggestions how to achieve this would be helpful. Thank you.