访问数组中的字典

时间:2020-05-16 21:53:46

标签: arrays vba dictionary

我创建了一个函数CreateArrayOfDicts(),该函数返回字典数组。现在,我正在努力访问另一个子目录中的字典。如何访问其中一个词典,尤其是每个词典中专用键下的值?

“类别”

是字典中的键之一

 Sub EditDataSeriesParams()
    Dim mySeries As Series
    Dim key As Variant
    catparams = CreateArrayofDicts() ' array of dictionaries
    Dim ws As Worksheet
    Set ws = Sheets("Sheet1")

    i = 7
    'Debug.Print ws.Cells(7, 21)

    Do Until IsEmpty(ws.Cells(i, 21))
        For Each mySeries In ActiveSheet.ChartObjects("Test").Chart.SeriesCollection
            For j = 0 To UBound(catparams) 'entering array of dictionaries
                If ws.Cells(i, 21) = mySeries.Name And catparams(j).("Category") = mySeries.Name Then ' issue is here
                    mySeries.Select
                    Debug.Print 5
                    With Selection
                        .MarkerStyle = xlMarkerStyleTriangle
                        .MarkerSize = catparams(j)("Size") ' Size is a key in dict
                        .MarkerBackgroundColor = catparams(j)("Back") ' Back is a key in dict
                        .MarkerForegroundColor = catparams(j)("Front") ' Front is a key in dict

                    End With

                End If

            Next j
        Next mySeries

    i = i + 1
    Loop
End Sub

1 个答案:

答案 0 :(得分:2)

尝试不使用点,就像随后在代码中所做的一样……

catparams(j)("Category") = mySeries.Name
相关问题