VBA:粘贴不同名称的图表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17169049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 21:43:31 来源:igfitidea点击:
VBA: Paste chart with a different name
提问by Eduard Florinescu
I use VBA to copy and paste a chart.
我使用 VBA 复制和粘贴图表。
ActiveSheet.ChartObjects("Chart1").Activate
ActiveChart.ChartArea.Copy
ActiveSheet.PasteSpecial Format:="Microsoft Office Drawing Object", Link:= _
False, DisplayAsIcon:=False
The problem is that I end up having two charts with the same name ("Chart1"
), and when I try to rename them after:
问题是我最终有两个具有相同名称 ( "Chart1"
) 的图表,当我尝试将它们重命名为:
'ActiveSheet.Shapes("Chart1").Name = CHART_NAME
They both get renamed.
他们都改名了。
How can I paste the chart with a different name.
如何粘贴具有不同名称的图表。
回答by dee
And what about using Duplicate()?
那么使用 Duplicate() 呢?
Dim source As ChartObject
Set source = ActiveSheet.ChartObjects("Chart1")
Dim newChart As Object
Set newChart = source.Duplicate
newChart.Name = "newChartName"