即使我正在引用我在代码中使用的工作表,我也会收到此 VBA 错误。我不经常使用 VBA,所以这可能是一个简单的问题。
Sub ParseJSON()
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("B2").Value
'Parse it
Set jsonObj = JSON.parse(jsonText)
'Set the starting row where to put the values
currentRow = 5
'First column where to put the values
startColumn = 1 'A
'For i = 1 To jsonObj.Count
'ws.Cells(currentRow, startColumn) = jsonObj
'Next i
For Each strKey In jsonObj.keys()
With ws
Range("A", strKey) = jsonObj(strKey)
End With
Next
'ws.Range("A", strKey).Activate = jsonObj(strKey)
'Get the rows collection
'agencyID = jsonObj("agencyID")
'agencyName = jsonObj("agencyName")
'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(5, 5) = agencyID
'Next i
'Increment the row to the next one
'currentRow = currentRow + 1
'Next jsonRow
End Sub
我在这条线上得到了错误
With ws
Range("A", strKey) = jsonObj(strKey)
End With
方法'对象范围'_Global'失败
有谁知道如何解决这个问题?