und wie so oft - kaum macht man es richtig ... schon funktioniert es !!
Funktioniert hat das Setzen der Eigenschaft aber auch bereits in xl2002, das wird mit dem Code oben auch so gemacht.
Und die Option zum einstellen steht auch in xl2007 schon über die Optionen der PT zur Verfügung, nicht erst seit xl2010.
Funktioniert hat das Setzen der Eigenschaft aber auch bereits in xl2002, das wird mit dem Code oben auch so gemacht.
Sub DeleteOldPivotItemsWB()
'löschen von nicht mehr verwendeten Einträgen in Pivot-Tabellen
'basierend auf MSKB (Q202232)
'Quelle: Thomas Ramel
Dim ws As Worksheet
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
On Error Resume Next
'als Alternative ab xl2002
If Val(Application.Version) > 9 Then
For Each ws In ActiveWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.ManualUpdate = True
pt.RefreshTable
pt.PivotCache.MissingItemsLimit = xlMissingItemsNone
pt.ManualUpdate = False
Next pt
Next ws
Else
For Each ws In ActiveWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.ManualUpdate = True
pt.RefreshTable
For Each pf In pt.PivotFields
For Each pi In pf.PivotItems
If pi.RecordCount = 0 And _
Not pi.IsCalculated Then
pi.Delete
End If
Next pi
Next pf
pt.ManualUpdate = False
Next pt
Next ws
End If
End Sub