在时间表内同时刷新外部数据源和数据透视表 [英] refresh both the External data source and pivot tables together within a time schedule

查看:194
本文介绍了在时间表内同时刷新外部数据源和数据透视表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我最后一篇文章首次运行时自动刷新可转换数据,我发现在我的第一次执行 查询 外部数据源被刷新,大约需要1分钟执行。在第二次运行中,数据透视表已更新。



是否有解决方案( VBA代码)来刷新外部数据源和点击命令按钮

解决方案(假设我们设置了一个计时器)方案

在连接属性下,取消选中启用后台刷新。这将使连接刷新时被告知,而不是在后台执行其他进程。



禁用后台刷新,您的VBA过程将等待您的外部数据刷新然后转到下一行代码。



然后您只需修改以下代码:

  ActiveWorkbook.Connections(CONNECTION_NAME)。刷新
表(SHEET_NAME)。数据透视表(PIVOT_TABLE_NAME)。PivotCache.Refresh
pre>

您还可以关闭VBA中的后台刷新:

  ActiveWorkbook.Connections(CONNECTION_NAME)。ODBCConnection.BackgroundQuery = False 


In my last post Auto refresh pivottables data in excel on first run, i found that on my first execution the query from the External data source is refreshed and takes approximately 1 min to execute. and in my second run, the pivot tables are updated.

Is there a solution (VBA code) to refresh both the External data source and pivot tables together within a time schedule (If suppose we set a timer) by clicking command button?

解决方案

Under the connection properties, uncheck "Enable background refresh". This will make the connection refresh when told to, not in the background as other processes happen.

With background refresh disabled, your VBA procedure will wait for your external data to refresh before moving to the next line of code.

Then you just modify the following code:

ActiveWorkbook.Connections("CONNECTION_NAME").Refresh
Sheets("SHEET_NAME").PivotTables("PIVOT_TABLE_NAME").PivotCache.Refresh

You can also turn off background refresh in VBA:

ActiveWorkbook.Connections("CONNECTION_NAME").ODBCConnection.BackgroundQuery = False

这篇关于在时间表内同时刷新外部数据源和数据透视表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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