Error copying waterfall charts with Excel macro

[亡魂溺海] 提交于 2019-12-23 05:41:41

问题


I have some simple VBA code that loops through a range of graphs in my Excel workbook and copies them to a PowerPoint presentation. It works great for all graphs except for waterfall graphics (Error 445: “Object doesn't support this option”). Since they're relatively new to Excel, I thought there might be an issue of compatibility and was wondering if there was a workaround.

Thanks !!

'Bar chart ==> works fine
ActiveWorkbook.Sheets(7).ChartObjects("Graphique 1").Copy
' Waterfall chart ==> Error 445
ActiveWorkbook.Sheets(8).ChartObjects("Graphique 1").Copy

Edit: When I try to record the procedure with Excel's macro recorder, it gives me the same lines of code, but when executing the code, I get the same error.

ActiveSheet.ChartObjects("Graphique 1").Activate
Selection.Copy

回答1:


I've tested with the waterfall chart and it does seem like VBA is not able to copy that type of chart.

Potential fixes: You're able to copy as a picture using .copyPicure or you can make a workaround by using:

YourchartObject.duplicate.select
selection.cut

and then pasting to the Powerpoint.




回答2:


tldr; I stumbled on the following, which works for all charts, including waterfalls and other new Excel charts:

ActiveSheet.Shapes("Any Chart").Copy

Here is how to copy most Excel charts:

ActiveSheet.ChartObjects("My Chart").Copy

ActiveSheet.ChartObjects("My Chart").Chart.ChartArea.Copy

However, neither of the above work with a waterfall chart or other newer Excel chart.

If you record a macro while copying a waterfall chart, this is what you get:

Sub RecordedMacro1()
'
' Recorded while copying Waterfall chart
'
    ActiveSheet.ChartObjects("Waterfall Chart").Activate
    Selection.Copy
End Sub

This also also does not work with a waterfall chart.

There's plenty of other tried and true chart-related VBA that doesn't work with the newer Excel charts.



来源:https://stackoverflow.com/questions/54198822/error-copying-waterfall-charts-with-excel-macro

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!