vba 如何将形状复制到另一个工作表(不是图片)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9465124/
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
How to copy a Shape to another worksheet (not as a picture)?
提问by adrien.pain
I'm having a bit of a trouble (once again...) with Excel VBA.
我在使用 Excel VBA 时遇到了一些麻烦(再次......)。
I just want to copy Shapes (which are in fact "templates" shapes, with pre-defined layout) from a Worksheet to another Worksheets.
我只想将形状(实际上是具有预定义布局的“模板”形状)从工作表复制到另一个工作表。
When I record a macro, this is the generated VBA code :
当我录制宏时,这是生成的 VBA 代码:
Sheets("Layout").Select
ActiveSheet.ChartObjects("CHART_TEMPLATE").Activate
ActiveChart.ChartArea.Copy
Sheets("Example").Select
Range("A1").Select
ActiveSheet.Paste
Of course, I want to get rid of all ".Select"
methods, for performance issue. For this reason, I can't Select
a range, neither use ActiveSheet.Paste
当然".Select"
,为了性能问题,我想摆脱所有方法。出于这个原因,我不能确定Select
范围,也不能使用ActiveSheet.Paste
Unfortunately, the Paste
method only exists for Worksheet
objects (like ActiveSheet.Paste
), so I had to use the PasteSpecial
method of Range
objects.
不幸的是,该Paste
方法只存在于Worksheet
对象(如ActiveSheet.Paste
),所以我不得不使用对象的PasteSpecial
方法Range
。
So here's my code :
所以这是我的代码:
ThisWorkbook.Sheets("Layout").ChartObjects("CHART_TEMPLATE").Copy
ThisWorkbook.Sheets("Example").Range("A1").PasteSpecial Paste:=xlPasteAll
But, the PasteSpecial
method copies Shapes
as pictures...
Of course I don't want pictures, because I have to populate those Charts
with data.
但是,该PasteSpecial
方法复制Shapes
为图片......当然我不想要图片,因为我必须Charts
用数据填充那些。
Does someone have a clue here ?
有人在这里有线索吗?
Thanx,
谢谢,
回答by assylias
The Paste method can take a destination as an argument. Have you tried something like this?
Paste 方法可以将目标作为参数。你有没有尝试过这样的事情?
ThisWorkbook.Sheets("Example").Paste Destination:=ThisWorkbook.Sheets("Example").Range("A1")