我使用以下代码插入图表。我现在如何参考上述图表?我知道我应该使用ChartObject,但是如何设置它?
更具体地说,我想将图表分配给变量,但我不确定如何做到这一点。我试过了:
set myChart = ActiveSheet.Shapes.AddChart(xlLine, 500, 420, , 175)
但无济于事。
Sub InsertInfection(rngToPrint As Range, lngTopLeft As String, BottomLeft As String)
Dim strRange As String
Dim rngChart As Range
Dim myChart As ChartObject
lngStartRow = Sheets(rngToPrint.Worksheet.Name).Range(lngTopLeft).Row
lngEndRow = Sheets(rngToPrint.Worksheet.Name).Range(BottomLeft).Row
Sheets(rngToPrint.Worksheet.Name).Activate
Sheets(rngToPrint.Worksheet.Name).Range("$A$" & CStr(lngStartRow) & ":$D$" & CStr(lngEndRow)).Select
ActiveSheet.Shapes.AddChart(xlLine, 500, 420, , 175).Select
End Sub
答案 0 :(得分:2)
喜欢这个
Dim myChart as Chart
set myChart = ActiveSheet.Shapes.AddChart(xlLine, 500, 420, , 175).Chart
如果您需要ChartObject
的引用,请使用myChart.Parent