更改 excel xyscatter 图中数据系列的颜色

Change color of data series in excel xyscatter chart

我正在尝试更改 excel 图表中数据点的颜色,但我尝试的一切都不成功。

这是我试过的一种方法,但点仍然显示为蓝色:

With Chrt
.ChartType = xlXYScatter
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).Delete
Loop
    .SeriesCollection.NewSeries

                .SeriesCollection(1).Name = "=""Top Platen"""
                .SeriesCollection(1).Values = yaxis
                .SeriesCollection(1).XValues = xaxis

                ActiveChart.SeriesCollection(1).Select
                 With Selection.Format.Fill
                    .Visible = msoTrue
                    .ForeColor.RGB = RGB(255, 0, 0)
                    .Transparency = 0
                    .Solid
                End With

这是我尝试过的另一种方法,但数据点仍然显示为蓝色:

With Chrt
.ChartType = xlXYScatter
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).Delete
Loop
    .SeriesCollection.NewSeries

                .SeriesCollection(1).Name = "=""Top Platen"""
                .SeriesCollection(1).Values = yaxis
                .SeriesCollection(1).XValues = xaxis
                .SeriesCollection(1).Interior.Color = RGB(255,0,0)

这只是我的代码的一部分,如有必要我可以提供其他区域。任何帮助将不胜感激。

我认为问题在于嵌套的 With 块变得混乱。这是解决它的一种方法,仍然使用嵌套 With 块:

With Chrt
    .ChartType = xlXYScatter

    Do Until .SeriesCollection.Count = 0
        .SeriesCollection(1).Delete
    Loop

    .SeriesCollection.NewSeries

    With .SeriesCollection(1)
        .Name = "=""Top Platen"""
        .Values = yaxis
        .XValues = xaxis
        .Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
    End With
End With

这里 Microsoft's documentation link 讨论完全限定的嵌套 With 块。