vba 将图表从一张纸复制到另一张纸

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45190863/
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-12 12:55:42  来源:igfitidea点击:

Copy Charts from one sheet to another

excelvbaexcel-vba

提问by Jenny

I have two Sheets, and would like to copy the Chart from sheet1 to sheet2.

我有两张工作表,想将图表从工作表 1 复制到工作表 2。

I am using the below code, the code is removing the Chart from Sheet1 and pasting them into sheet2. Instead, I would just like to have the duplicate of the Chart.

我正在使用下面的代码,该代码正在从 Sheet1 中删除图表并将它们粘贴到 sheet2 中。相反,我只想拥有图表的副本。

ALso, I would like to have my Charts in particular range. How can I edit them ?

另外,我希望我的图表在特定范围内。我该如何编辑它们?

Anylead would be helpful

Anylead 会有所帮助

 Sub overview1()
    Dim chartobj As Object
    For Each chartobj In Sheets("CAT").ChartObjects
    chartobj.chart.Location xlLocationAsObject, "Overview_1"

    Next chartobj
    For Each chartobj In Sheets("Dev").ChartObjects
    chartobj.chart.Location xlLocationAsObject, "Overview_1"
    Next chartobj
End sub

回答by Netloh

You should try to make use of a copy/paste technique, like the below.

您应该尝试使用复制/粘贴技术,如下所示。

Sub overview1()
    Dim OutSht As Worksheet
    Dim Chart As ChartObject
    Dim PlaceInRange As Range

    Set OutSht = ActiveWorkbook.Sheets("Overview_1") '<~~ Output sheet
    Set PlaceInRange = OutSht.Range("B2:J21")        '<~~ Output location

    'Loop charts
    For Each Chart In Sheets("CAT").ChartObjects
        'Copy/paste charts
        Chart.Copy
        OutSht.Paste PlaceInRange
    Next Chart

End Sub

This is just a simple example which should keep you going. Obviously this example pastes all charts in the exact same locataion in the output sheet, which probably isn't what you are looking for.

这只是一个简单的例子,应该会让你继续前进。显然,此示例将所有图表粘贴到输出表中完全相同的位置,这可能不是您要查找的内容。