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
推荐答案
我总是觉得复制图表令人困惑,但我认为这可以满足您的需求,并且不使用任何 Selects
,它总是很好.
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屋!
查看全文