Excel VBA Line Color / Marker Line Color

前端 未结 3 644
无人共我
无人共我 2020-12-20 12:47

I\'m writing some VBA code to modify Excel charts. For a scatter chart I need to modify the marker line colour and sometimes the line colour of the connecting lines. I can d

3条回答
  •  温柔的废话
    2020-12-20 13:36

    The line colour of the connecting lines is Series.Format.Line.ForeColor. The marker line colour is Series.MarkerForegroundColor. But at least with Excel 2007 there is a problem with setting Series.Format.Line.ForeColor. See example:

    Sub Macro3()
     Dim oChart As Chart
     Dim oSeries As Series
    
     Set oChart = ActiveChart
     Set oSeries = oChart.SeriesCollection(2)
    
     oSeries.Format.Line.Weight = 5 'Line.Weigth works ever
    
     oSeries.Format.Line.Visible = msoFalse 'for Line.ForeColor getting to work we have to cheat something
     oSeries.Format.Line.Visible = msoTrue
     oSeries.Format.Line.ForeColor.RGB = RGB(0, 255, 0) 'now it works
    
     oSeries.MarkerSize = 15
     oSeries.MarkerBackgroundColor = RGB(255, 0, 0) 'marker background
    
     oSeries.MarkerForegroundColor = RGB(0, 0, 255) 'marker foreground (lines around)
    End Sub
    

    The ActiveChart is a scatter chart. And this is tested with Excel 2007.

提交回复
热议问题