4

我正在从同一来源创建各种图表。我希望能够用 vba 将每个图表剪切粘贴为图片。有谁知道正确的代码?

我试过这个,但它不起作用:

Range("B21:C22").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Graphs'!$B$21:$C$22")
ActiveChart.ChartType = xl3DPie
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
ActiveSheet.Pictures.Paste.Select
4

3 回答 3

10

我总是觉得复制图表令人困惑,但我认为这可以满足您的需求,并且不使用 any Selects,这总是很好的。

Sub CreateAndCopyChart()
Dim ws As Worksheet
Dim cht As Chart

Set ws = ThisWorkbook.Worksheets("Graphs")
Set cht = ws.Shapes.AddChart.Chart
With cht
    .SetSourceData ws.Range("$B$21:$C$22")
    .ChartType = xl3DPie
    .ChartArea.Copy
End With
ws.Range("A2").PasteSpecial xlPasteValues
cht.Parent.Delete
End Sub
于 2012-11-11T01:01:20.833 回答
1
Range("A1:A8").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Sheet1'!$A$1:$A$8")
ActiveChart.ChartType = xlLine
ActiveChart.PlotArea.Select
ActiveChart.ChartArea.Copy


Range("A20").Select
ActiveSheet.Paste
于 2012-11-11T00:55:09.363 回答
0

有点慢,但可以让您将图表转换为图片。我使用它来创建报告(在之前的步骤中,我从另一个选项卡复制图表,其中创建了原始图表)

ActiveSheet.ChartObjects.Select 
Selection.Copy                        'copy charts 
Range("A1").Select                    'choose destination
ActiveSheet.Pictures.Paste.Select     'paste as pictures
ActiveSheet.ChartObjects.Delete       'delete charts (leaving just pictures)
于 2019-04-16T10:55:11.190 回答