Refreshing all the pivot tables in my excel workbook with a macro

前端 未结 10 1335
长发绾君心
长发绾君心 2020-11-29 20:32

I have a workbook with 20 different pivot tables. Is there any easy way to find all the pivot tables and refresh them in VBA?

10条回答
  •  一生所求
    2020-11-29 20:49

    ActiveWorkbook.RefreshAll refreshes everything, not only the pivot tables but also the ODBC queries. I have a couple of VBA queries that refer to Data connections and using this option crashes as the command runs the Data connections without the detail supplied from the VBA

    I recommend the option if you only want the pivots refreshed

    Sub RefreshPivotTables()     
      Dim pivotTable As PivotTable     
      For Each pivotTable In ActiveSheet.PivotTables         
        pivotTable.RefreshTable     
      Next 
    End Sub 
    

提交回复
热议问题