我正在使用相同的来源创建各种图表。我希望能够将每个图表的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
答案 0 :(得分:10)
我总觉得复制图表令人困惑,但我认为这样做符合您的要求,并且不使用任何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
答案 1 :(得分: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
答案 2 :(得分: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)