pivottable.ManualUpdate [ = setting ]
True causes RefreshTable to clear data from the pivot table, rather than refreshing it
False allows RefreshTable to work normally.
Default is False.
This property is reset to False automatically after the calling procedure ends (important)
This property should be set to true just before you make an update (e.g. changing pivot item Visible property)
So your code would look like:
For i = 1 To oPivotField.PivotItems.Count
If (oPivotField.PivotItems(i).Name = "TestCondition") Then
oPivotField.Parent.ManualUpdate = True
oPivotField.PivotItems(i).Visible = True 'doesn't recalculate pivot table because ManualUpdate is set to True
Else
oPivotField.Parent.ManualUpdate = True
oPivotField.PivotItems(i).Visible = False 'doesn't recalculate pivot table because ManualUpdate is set to True
End If
Next
'setting pivot table ManualUpdate property to False might be redundant at this point because it gets reset to false immediately after you set Visible property of oPivotField
oPivotField.Parent.ManualUpdate = False
oPivotField.Parent.Update()
As a conclusion, ManualUpdate property change doesn't stay for long (in my tests, I could see that it gets reset to false as soon as possible, so that's why I recommended you to set it to true whenever you want to make a change for a pivot item)
Excel での更新の意味の詳細については、次を確認してください:
ピボット更新と更新 – 本当の違いはありますか?
参考資料:
タイトル: VBA と .NET を使用した Excel のプログラミング 作成
者: Jeff Webb、Steve Saunders
印刷 ISBN: 978-0-596-00766-9 | ISBN 10: 0-596-00766-3
電子ブック ISBN: 978-0-596-15951-1 | ISBN 10: 0-596-15951-X