如何创建按钮以刷新数据透视表 table

How create button to refresh pivot table

我想创建一些按钮,以便在数据更改后刷新我的数据透视表 table。但是我的代码删除了所有日期并将模板留空。这是我的代码。我该如何解决这个问题

Sub RefreshAllPivots()

Dim pc as PivotCache
For each pc in thisWorkbook.PivotCaches

Pc.resfresh
Next pc
End sub

这应该可以做到。

ThisWorkbook.RefreshAll

或者,遍历每一个。

Dim Sheet as WorkSheet, Pivot as PivotTable
For Each Sheet in ThisWorkbook.WorkSheets
    For Each Pivot in Sheet.PivotTables
        Pivot.RefreshTable
        Pivot.Update
    Next
Next