简体   繁体   English

运行时错误'-2147024809(80070057)'具有不稳定的行为

[英]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.

相关问题 ListBox.Selected无法正常工作; 运行时错误'-2147024809(80070057) - ListBox.Selected is not working; Run-time error '-2147024809(80070057) clsCommandButton:Microsoft Excel VBA-运行时错误'-2147024809(80070057)' - clsCommandButton: Microsoft Excel VBA - Run-Time Error '-2147024809 (80070057)' 更改共享工作簿上的按钮文本:运行时错误“-2147024809 (80070057)” - Changing button text on a shared workbook: Run-Time Error '-2147024809 (80070057)' 将Excel数据导入PowerPoint幻灯片-运行时错误'-2147024809(80070057)':指定的值超出范围 - Importing Excel data into PowerPoint slides - Run-time error '-2147024809 (80070057)': The specified value is out of range 运行时错误-2147024809(80070057)指定的值超出形状范围 - run time error -2147024809 (80070057) the specified value is out of range with shape 运行时错误“-2147024809(80070057)”指定的值超出范围 - run time error '-2147024809(80070057)' the specified value is out of range VBA运行时错误-214724809(80070057) - VBA Run-time error -214724809 (80070057) 旧代码1004、424,-2147024809中的新运行时错误(80070057) - New run time errors in older code 1004, 424, -2147024809 (80070057) 运行时错误-2147024809(80070057):调整形状 - runtime error -2147024809 (80070057): Resizing shape 获取系统错误 &H80070057 (-2147024809) - Getting System Error &H80070057 (-2147024809)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM