简体   繁体   English

使用VBA宏刷新Excel工作簿中的所有数据透视表

[英]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. 我的excel文件包含30-40个数据透视表,并且更新所有数据都花费了太长时间。 Is there a way I can update it with just a push of a button using VBA macro? 有什么方法可以使用VBA宏按一下按钮来更新它吗?

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 . 在Excel 2007和2010中,可以通过按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. Ben Michael Oracion发布了VBA代码,他没有发布的是,如果要在触发RefreshAll之后运行一行VBA代码,可能会导致错误。 For this very reason I set the BackGroundQuery property to False beforehand. 因此,我事先将BackGroundQuery属性设置为False

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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