I downloaded the VB-JSON from JSON.org and have imported the "JSON.bas", "cJSONScript.cls" and "cStringBuilder.cls" to my project.
According to posts I've seen I also have added references to "Microsoft Scripting Runtime" and to "Microsoft ActiveX Data Objects 2.8 Library".
I also created the below "Test" macro from another poster to run my test.
I then copied my JSON data into A1 as that is were this macro looks for the JSON to parse.
However, I can not seem to get past an "Object required" error on the line with;
Set jsonRows = jsonObj("rows")
I'm running Excel 2007 and VBA 6.5.
Any insights would be VERY appreciated.
FYI: I'm completely new to JSON and relatively new to VBA.
Thanks
Bill
Sub Test()
Dim jsonText As String
Dim jsonObj As Dictionary
Dim jsonRows As Collection
Dim jsonRow As Collection
Dim ws As Worksheet
Dim currentRow As Long
Dim startColumn As Long
Dim i As Long
Set ws = Worksheets("Sheet1")
'Create a real JSON object
jsonText = ws.Range("A1").Value
'Parse it
Set jsonObj = JSON.parse(jsonText)
'Get the rows collection
Set jsonRows = jsonObj("rows") <---- errors here
'Set the starting row where to put the values
currentRow = 1
'First column where to put the values
startColumn = 2 'B
'Loop through all the values received
For Each jsonRow In jsonRows
'Now loop through all the items in this row
For i = 1 To jsonRow.Count
ws.Cells(currentRow, startColumn + i - 1).Value = jsonRow(i)
Next i
'Increment the row to the next one
currentRow = currentRow + 1
Next jsonRow
End Sub
According to posts I've seen I also have added references to "Microsoft Scripting Runtime" and to "Microsoft ActiveX Data Objects 2.8 Library".
I also created the below "Test" macro from another poster to run my test.
I then copied my JSON data into A1 as that is were this macro looks for the JSON to parse.
However, I can not seem to get past an "Object required" error on the line with;
Set jsonRows = jsonObj("rows")
I'm running Excel 2007 and VBA 6.5.
Any insights would be VERY appreciated.
FYI: I'm completely new to JSON and relatively new to VBA.
Thanks
Bill
Sub Test()
Dim jsonText As String
Dim jsonObj As Dictionary
Dim jsonRows As Collection
Dim jsonRow As Collection
Dim ws As Worksheet
Dim currentRow As Long
Dim startColumn As Long
Dim i As Long
Set ws = Worksheets("Sheet1")
'Create a real JSON object
jsonText = ws.Range("A1").Value
'Parse it
Set jsonObj = JSON.parse(jsonText)
'Get the rows collection
Set jsonRows = jsonObj("rows") <---- errors here
'Set the starting row where to put the values
currentRow = 1
'First column where to put the values
startColumn = 2 'B
'Loop through all the values received
For Each jsonRow In jsonRows
'Now loop through all the items in this row
For i = 1 To jsonRow.Count
ws.Cells(currentRow, startColumn + i - 1).Value = jsonRow(i)
Next i
'Increment the row to the next one
currentRow = currentRow + 1
Next jsonRow
End Sub