运行时错误“1004”:无法设置 PivotItem 类的 Visible 属性
Excel VBA:
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set pf = pt.PivotFields("Snapshot Date")
For Each pi In pf.PivotItems
If pi.Name <> "(blank)" Then
pi = DateValue(pi) 'I have tried using Cdate, Cdbl, Cstr as well.
End If
Next pi
错误发生在这里:
i = 1
Do Until i >= pf.PivotItems.count - 1
For Each pi In pf.PivotItems
pi.Visible = False 'Error here
Next pi
pf.PivotItems(i).Visible = True '.. And here!
pf.PivotItems(i + 1).Visible = True
Loop
数据透视项目是日期,不确定是否需要在打开/关闭可见性之前对其进行格式化?
我无休止地用谷歌搜索,找不到任何解决方案:(关于非连续项目的一些东西,但我不太明白。