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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 15:21:02  来源:igfitidea点击:

How to copy a Shape to another worksheet (not as a picture)?

excelvba

提问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 Selecta range, neither use ActiveSheet.Paste

当然".Select",为了性能问题,我想摆脱所有方法。出于这个原因,我不能确定Select范围,也不能使用ActiveSheet.Paste

Unfortunately, the Pastemethod only exists for Worksheetobjects (like ActiveSheet.Paste), so I had to use the PasteSpecialmethod of Rangeobjects.

不幸的是,该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 PasteSpecialmethod copies Shapesas pictures... Of course I don't want pictures, because I have to populate those Chartswith 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")