简体   繁体   中英

Refresh all Pivot Tables in Excel Workbook using VBA Macro

My excel file holds 30-40 pivot tables and its taking too long to update it all. Is there a way I can update it with just a push of a button using VBA macro?

It would be nice if I could assign a shortcut key for this macro to refresh all the pivots. One shot deal, maybe?

In Excel 2007 and 2010 you can update them by pressing Ctrl+Alt+F5 .
Ben Michael Oracion has posted the VBA code, what he didn't post is that if you want to run a single line of VBA code after the RefreshAll is triggered it may cause a bug. For this very reason I set the BackGroundQuery property to False beforehand.

Dim piv As PivotCache
For Each piv In ActiveWorkbook.PivotCaches 'beállítja hogy ne legyen háttérben frissítés, így nem fut bug-ra
    piv.BackgroundQuery = False
Next

ActiveWorkbook.RefreshAll 'Frissít minden pivotot (és táblát)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM