作者:李劲松在科岛每晚包夜 | 来源:互联网 | 2023-05-21 14:39
目的是在重新计算单元格后刷新Excel中的所有图表.
我使用Microsoft Excel 2010.
我们知道,有一个错误?在Excel中,即使之后Excel也不会更新图表
Application.CalculateFullRebuild
一个已知的黑客是做这样的事情:
Application.ScreenUpdating = False
Temp = ActiveCell.ColumnWidth
ActiveCell.Columns.AutoFit
ActiveCell.ColumnWidth = Temp
Application.ScreenUpdating = True
这确实有效.但是,所有Excel图表都会闪烁(更新时它们会变白).你能告诉我,有什么方法可以避免这种眨眼吗?
我试着打电话
.Refresh
在所有图表上(https://msdn.microsoft.com/en-us/library/office/ff198180(v=office.14).aspx):
For Each ChartObject In ActiveSheet.ChartObjects
ChartObject.Refresh
Next
但由于某种原因,我的Excel(2010)显示错误#438"对象不支持此属性或方法".
你能告诉我,我是否会错过重要的事情?
1> 小智..:
未经测试但.Refresh可能适用于此:
Sub ChangeCharts()
Application.ScreenUpdating = False 'This line disable the on screen update for better performance, the blink you see, you could delete both lanes but it will run slower
Dim myChart As ChartObject
For Each myChart In ActiveSheet.ChartObjects
myChart.Chart.Refresh
Next myChart
Application.ScreenUpdating = True'This line reenable the on screen update for better performance, the blink you see, you could delete both lanes but it will run slower
End Sub
这是因为(正如您提供的链接所示).Refresh仅适用于对象Chart,而不适用于您尝试应用它的对象ChartObjects.希望它能引导你朝着正确的方向前进.(还在代码中添加了屏幕上闪烁/闪烁的引号)