使用VBA宏刷新Excel工作簿中的所有数据透视表 [英] Refresh all Pivot Tables in Excel Workbook using VBA Macro

查看:440
本文介绍了使用VBA宏刷新Excel工作簿中的所有数据透视表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的excel文件可容纳30-40个数据透视表,并且更新所有文件的时间过长.有什么方法可以使用VBA宏按一下按钮来更新它吗?

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?

推荐答案

在Excel 2007和2010中,您可以通过按 Ctrl + Alt + F5 来更新它们.
Ben Michael Oracion发布了VBA代码,他没有发布的是,如果要在触发 RefreshAll 后运行一行VBA代码,可能会导致错误.由于这个原因,我事先将 BackGroundQuery 属性设置为 False .

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)

这篇关于使用VBA宏刷新Excel工作簿中的所有数据透视表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆