用vba在工作表中新建图表的方法有很多种。
一、用Shapes对象的AddChart方法(该方法已经被作废,但是仍然可以使用)
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Sub exceloffice() '作者QQ:1722187970,微信:xycgenius,微信公众号exceloffice Dim oChart As Chart Dim oSP As Shape Dim oWK As Worksheet Set oWK = Excel.ActiveSheet With oWK If .ChartObjects.Count > 0 Then '先删除所有图表 .ChartObjects.Delete End If Set oSP = .Shapes.AddChart(xlColumnClustered, 0, 0, 300, 300) Set oChart = oSP.Chart With oChart .SetSourceData oWK.Range("A1").CurrentRegion End With End With End Sub |