VBA-excel粘贴图为图片 [英] VBA-excel paste chart as a picture
本文介绍了VBA-excel粘贴图为图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从同一个来源创建各种图表。我想要能够削减贴纸与vba每个图表作为图片。有没有人知道正确的代码?
I am creating various charts from the same source. I would like to be able to cut paste with vba each chart as a picture. Does anyone know the right code?
我试过了,但它不工作:
I tried with this but it does not work:
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
推荐答案
我总是发现复制图表令人困惑,但这是你想要的, t使用任何选择
,这总是很好。
I always find copying charts confusing, but this does what you want, I think, and doesn't use any Selects
, which is always nice.
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
这篇关于VBA-excel粘贴图为图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文