0

コードで使用しているワークシートを参照しているにもかかわらず、この 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

メソッド 'Range of object' _Global' が失敗しました

スクリーンショット

誰でもこれを解決する方法を知っていますか?

4

1 に答える 1