Workbook.RefreshAll 是否刷新数据透视表或数据透视缓存?
Does Workbook.RefreshAll refresh PivotTables or PivotCaches?
如果一个工作簿有 100 个数据透视表都使用一个缓存,Workbook.RefreshAll 会启动 100 次刷新还是只启动 1 次?
这是一个有趣的问题。我最近在 mrexcel.com 上发现了一个 post 询问关于循环通过每个枢轴 table 并单独更新每个枢轴或使用 .RefreshAll
.
的差异
Jerry Sullivan post编辑了一个答案(2011 年 8 月 16 日),其中包含以下评论(版本 #2 --> .RefreshAll
、版本 #1 --> 循环通过 pt's ):
The version #2 is probably more efficient. In addition to not stepping through each sheet, it probably updates each PivotCache once, whereas if any PivotTables share the same PivotCaches, those PivotCaches will get refreshed more than once with version #1.
不过,我确实注意到他说 "probably"。
回答此类问题的最简单方法是编写一些代码并进行测试。
Sub RefreshTest()
Dim TimeTaken As Date
TimeTaken = Now()
ActiveWorkbook.RefreshAll
TimeTaken = Now() - TimeTaken
Debug.Print Now() & vbTab & "Refresh All" & vbTab & Format(TimeTaken, "HH:MM:SS") & " seconds."
TimeTaken = Now()
ActiveWorkbook.PivotCaches(1).Refresh
TimeTaken = Now() - TimeTaken
Debug.Print Now() & vbTab & "Refresh Specific Cache" & vbTab & Format(TimeTaken, "HH:MM:SS") & " seconds."
End Sub
在我的 PC 上测试具有 1048575 行的数据透视表时,使用 RefreshAll 和刷新数据透视表之一的数据透视缓存之间没有区别。
如果一个工作簿有 100 个数据透视表都使用一个缓存,Workbook.RefreshAll 会启动 100 次刷新还是只启动 1 次?
这是一个有趣的问题。我最近在 mrexcel.com 上发现了一个 post 询问关于循环通过每个枢轴 table 并单独更新每个枢轴或使用 .RefreshAll
.
Jerry Sullivan post编辑了一个答案(2011 年 8 月 16 日),其中包含以下评论(版本 #2 --> .RefreshAll
、版本 #1 --> 循环通过 pt's ):
The version #2 is probably more efficient. In addition to not stepping through each sheet, it probably updates each PivotCache once, whereas if any PivotTables share the same PivotCaches, those PivotCaches will get refreshed more than once with version #1.
不过,我确实注意到他说 "probably"。
回答此类问题的最简单方法是编写一些代码并进行测试。
Sub RefreshTest()
Dim TimeTaken As Date
TimeTaken = Now()
ActiveWorkbook.RefreshAll
TimeTaken = Now() - TimeTaken
Debug.Print Now() & vbTab & "Refresh All" & vbTab & Format(TimeTaken, "HH:MM:SS") & " seconds."
TimeTaken = Now()
ActiveWorkbook.PivotCaches(1).Refresh
TimeTaken = Now() - TimeTaken
Debug.Print Now() & vbTab & "Refresh Specific Cache" & vbTab & Format(TimeTaken, "HH:MM:SS") & " seconds."
End Sub
在我的 PC 上测试具有 1048575 行的数据透视表时,使用 RefreshAll 和刷新数据透视表之一的数据透视缓存之间没有区别。