VBA中的PivotItem报告不存在的项目

我有一个VBA代码,通过更改透视filter(如下所示)来打印数据透视表。

我的问题是,打印最后一个PivotItem(pivF = 27)后,“pivI.Name”更改为“999”,这不存在于我的工作表和数据透视表中。 因此macros报告错误消息“运行时错误5”。

有趣的是,在同一个文件中的另一个工作表中相同的代码正常工作,没有错误!

任何人都可以帮我吗?

Private Sub CommandButton3_Click() Dim pivF As PivotField Dim pivI As PivotItem Set pivF = ActiveSheet.PivotTables("Tourenplan").PivotFields("Tour") Application.ScreenUpdating = False For Each pivI In pivF.PivotItems pivF.CurrentPage = pivI.Name ActiveWindow.SelectedSheets.PrintOut Next pivI Application.ScreenUpdating = True End Sub 

非常感谢,
迪欧

我昨天也有同样的问题

检查Pivot Table options (右键单击表格),在Data tab ,应该findRetain items deleted from the data source ,为Number of items to retain per fieldselectNone ,然后刷新。

如果不起作用,请更改设置(“ Data tab上的所有设置),保存,closures,再次打开,再次检查相同的选项,并将Number of items to retain per field设置为None