[英]Run-time error '-2147024809 (80070057)' with erratic behavior
I have a macro to create a chart and modify its properties. 我有一个宏来创建图表并修改其属性。
If I run the macro normally, I get the following error 如果我正常运行宏,我会收到以下错误
on the last line of this code 在这段代码的最后一行
Set ChtObj = Worksheets("summary").ChartObjects.Add(Left:=700, Top:=100, Width:=800, Height:=500)
With ChtObj
.chart.ChartType = xlColumnStacked
.chart.SetSourceData Source:=Range("statistics!A101:C" & targetRow)
.Name = "waterfall"
End With
ActiveSheet.ChartObjects("waterfall").Activate
However, if I try to run the code step by step, I get no errors at all and all goes smoothly. 但是,如果我尝试逐步运行代码,我根本没有错误,一切顺利。 Where is the issue? 问题在哪里?
Write Worksheets("summary").Activate
on the top of your code, it should work. 编写Worksheets("summary").Activate
代码顶部,它应该工作。
The problem is that during the macro running, your active sheet is not "summary". 问题是在宏运行期间,您的活动工作表不是“摘要”。 In general, using Activesheet
is not a good practice in VBA - How to avoid using Select in Excel VBA . 通常,在VBA中使用Activesheet
不是一个好习惯 - 如何避免在Excel VBA中使用Select 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.