问题描述
我在使用Excel VBA时遇到了麻烦(再一次...).
I'm having a bit of a trouble (once again...) with Excel VBA.
我只想将一个工作表中的Shapes(实际上是具有预定义布局的模板"形状)复制到另一个工作表中.
I just want to copy Shapes (which are in fact "templates" shapes, with pre-defined layout) from a Worksheet to another Worksheets.
当我记录宏时,这是生成的VBA代码:
When I record a macro, this is the generated VBA code :
Sheets("Layout").Select
ActiveSheet.ChartObjects("CHART_TEMPLATE").Activate
ActiveChart.ChartArea.Copy
Sheets("Example").Select
Range("A1").Select
ActiveSheet.Paste
当然,我想摆脱所有".Select"
方法的性能问题.因此,我不能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
不幸的是,Paste
方法仅适用于Worksheet
对象(如ActiveSheet.Paste
),因此我不得不使用PasteSpecial
对象的PasteSpecial
方法.
Unfortunately, the Paste
method only exists for Worksheet
objects (like ActiveSheet.Paste
), so I had to use the PasteSpecial
method of Range
objects.
这是我的代码:
ThisWorkbook.Sheets("Layout").ChartObjects("CHART_TEMPLATE").Copy
ThisWorkbook.Sheets("Example").Range("A1").PasteSpecial Paste:=xlPasteAll
但是,PasteSpecial
方法将Shapes
复制为图片...当然,我不需要图片,因为我必须用数据填充这些Charts
.
But, the PasteSpecial
method copies Shapes
as pictures...Of course I don't want pictures, because I have to populate those Charts
with data.
有人在这里有线索吗?
感谢,
推荐答案
Paste方法可以将目标作为参数.你尝试过类似的东西吗?
The Paste method can take a destination as an argument. Have you tried something like this?
ThisWorkbook.Sheets("Example").Paste Destination:=ThisWorkbook.Sheets("Example").Range("A1")
这篇关于如何将Shape复制到另一个工作表(而不是图片)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!