散点图-有和无之间的可转换填充

问题描述

使用这些代码,我想制作带填充和不带填充标记的可转换XY散点图。 但是,一旦将标记转换为不填充并返回填充后,就不再将标记转换为不填充。 如果我保存并关闭,那么它将再次起作用。 您能推荐我需要更新的地方吗?

转换为不填充

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.FullSeriesCollection(1).Select
Selection.MarkerSize = 10
With Selection
    .Format.Fill.Visible = False
    .Format.Line.Visible = msoTrue
    .Format.Line.Weight = 1
    .Border.Linestyle = xlLinestyleNone 'Remove lines between points
End With

转换为填充

    ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.FullSeriesCollection(1).Select
Selection.MarkerSize = 10
With Selection
    .Format.Fill.Visible = msoTrue
    .Format.Fill.solid
    .Format.Fill.ForeColor.RGB = RGB(100,100,0)
    .Format.Line.Visible = msoTrue
    .Format.Line.Weight = 5
    .Border.Linestyle = xlLinestyleNone 'Remove lines between points
End With

谢谢。

解决方法

尝试

Sub test1()
    Dim Cht As Chart
    Dim Srs As Series
    
    Set Cht = ActiveSheet.ChartObjects("Chart 1").Chart
    Set Srs = Cht.SeriesCollection(1)
    
    With Srs
        .MarkerSize = 10
        .Format.Fill.Visible = msoFalse
        .Format.Line.Visible = msoFalse
        .Format.Line.Weight = 1
        .Border.LineStyle = xlLineStyleNone 'Remove lines between points
    End With
End Sub
Sub test2()
    Dim Cht As Chart
    Dim Srs As Series
    
    Set Cht = ActiveSheet.ChartObjects("Chart 1").Chart
    Set Srs = Cht.SeriesCollection(1)
    
    With Srs
        .MarkerSize = 10
        .Format.Fill.Visible = msoTrue
        .Format.Line.Visible = msoTrue
        .Format.Line.Weight = 5
        .Border.LineStyle = xlLineStyleNone 'Remove lines between points
    End With
End Sub