gpt4 book ai didi

excel - 数据透视图 - ActiveChart.Refresh 仅在调试时有效

转载 作者:行者123 更新时间:2023-12-02 15:52:54 28 4
gpt4 key购买 nike

我有一个 Excel 工作簿,我在其中根据现有数据透视表生成每个 VBA 的数据透视图。该图表被创建为新工作表。

到目前为止,结果符合预期。但是,当我转到生成的图表并想要在字段编辑器中更改某些内容时,我收到一条错误消息:

Pivot table report was saved without the underlying source data. Select "Refresh data", to refresh the report. (Translated from German)

完成此操作后,我可以在字段编辑器中工作。经过长时间令人紧张的调试 session 后,我发现我的代码在使用调试器单步执行时的行为有所不同。

  • 正常执行代码时,.Refresh 看似没有效果。
  • 使用调试器单步执行代码时,.Refresh 按预期工作,并且我在字段编辑器中没有收到错误消息。

我在 Excel 2010 和 2013 上进行了尝试。两个版本都显示相同的行为。

  Charts.Add    
chartSheetName = dqSource & "_PIVOT_CHART"
With ActiveChart
.Location where:=xlLocationAsNewSheet , Name:=chartSheetName
.HasTitle = True
.ChartTitle.Select
.ChartTitle.Text = "My chart title"
.Refresh ' <-- This is the suspect
End With

最佳答案

数据透视图依赖于数据透视表

我建议改为刷新该数据透视表的 PivotCache:

With myPivotTable
.PivotCache.Refresh
.PivotCache.MissingItemsLimit = xlMissingItemsNone
End With

关于excel - 数据透视图 - ActiveChart.Refresh 仅在调试时有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55451489/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com