Excel VBA-为什么更改枢纽项目的name属性会破坏枢轴单元对象?

时间:2018-07-31 17:19:23

标签: excel vba pivotitem

我有一段代码,其中我设置了对数据透视表对象的引用,然后更改了同一数据透视表中的数据透视表对象。进行更改后,pivotcell对象似乎已被破坏,但我不知道为什么或如何阻止这种情况发生

Sub test()

    Dim pc As PivotCell
    Dim pi As PivotItem

    'Set pivotcell object
    Set pc = ActiveCell.PivotCell

    For Each pi In pc.RowItems
        pi.Name = CStr(pi.Name) 'In the very first loop this destroys the pivotcell item
    Next pi

    pc.Range.Select 'Throws 'object required' (424) error

End Sub

0 个答案:

没有答案