根据文件(
https://docs.microsoft.com/en-us/office/vba/api/excel.sparklinegroups
):
“使用Range对象的SparkleGroups属性返回
父范围中现有的SparkleGroups集合。“
简而言之,创建迷你图后,可以通过父区域访问它们。在您的案例中,这可能类似于:
Set mySG = Range("A1:A4").SparklineGroups.Item(1)
下面是我可以从您的代码、宏记录器和文档(参见代码中的注释)中得到的结果。
Option Explicit
Private Sub SomeSparklines()
With ThisWorkbook.Worksheets("Sheet1")
' Refer to the sparkline group as soon as you create it.
With .Range("$A$1:$A$4").SparklineGroups.Add(Type:=xlSparkColumn, SourceData:="B1:E4")
.SeriesColor.Color = vbYellow
End With
' Loop through existing sparkline groups on Sheet1
' gaining access to the sparkline group via
' the variable you're looping with.
Dim sparkGroup As SparklineGroup
For Each sparkGroup In .Cells.SparklineGroups
sparkGroup.SeriesColor.Color = vbRed
Next sparkGroup
' Manipulate a specific sparkline group in
' cell A1 of worksheet Sheet1. For me, this manipulates
' the entire group (not just the sparkline in cell A1)
With .Range("A1").SparklineGroups.Item(1)
.SeriesColor.Color = vbBlack
' Do whatever stuff needs doing....
With .Points.Highpoint
.Visible = True
.Color.Color = vbGreen
End With
With .Points.Lowpoint
.Visible = True
.Color.Color = vbRed
End With
End With
End With
End Sub