Excel标记线图着色问题

我一直在研究一个macros在过去一周自动创build图表在Excel中。 我已经得到了很大的帮助(很大程度上得益于本网站及其用户的帮助),但是我陷入了一个看似微不足道的一步。 出于某种原因,我的线与标记图显示与它的变色。 我的意思是标记的中间填充是excel默认的标准蓝色。 我认为问题在于[.Visible = msoTrue]行,但无论如何操纵代码,我都无法使我的标记变成纯色。

代码如下

Sub DM1R_Graph() Dim ws As Worksheet For Each ws In Sheets ws.Activate If ws.Name <> "WSNs" Then Dim sht As Worksheet Dim xVals As Range, yVals As Range Dim co As Shape, cht As Chart, s As Series Set sht = ActiveSheet Set co = sht.Shapes.AddChart() Set cht = co.Chart 'remove any existing series Do While cht.SeriesCollection.Count > 0 cht.SeriesCollection(1).Delete Loop cht.ChartType = xlLineMarkers 'get the extent of the XValues... 'below is the first Y axis entry (Oil) '(change the 2nd offset number to get what you want) Set xVals = sht.Range(sht.Range("B2"), sht.Cells(Rows.Count, "B").End(xlUp)) Set yVals = xVals.Offset(0, 2) Set s = cht.SeriesCollection.NewSeries s.XValues = xVals s.Values = yVals With s.Format.Fill .Visible = msoTrue .ForeColor.RGB = RGB(0, 176, 80) .Transparency = 0 .Solid End With With s.Format.Line .Visible = msoTrue .ForeColor.RGB = RGB(0, 176, 80) .Transparency = 0 End With 'below is the second y axis entry (Gas) Set xVals = sht.Range(sht.Range("B2"), sht.Cells(Rows.Count, "B").End(xlUp)) Set yVals = xVals.Offset(0, 4) Set s = cht.SeriesCollection.NewSeries s.XValues = xVals s.Values = yVals With s.Format.Fill .Visible = msoTrue .ForeColor.RGB = RGB(255, 0, 0) .Transparency = 0 .Solid End With With s.Format.Line .Visible = msoTrue .ForeColor.RGB = RGB(255, 0, 0) .Transparency = 0 End With 'below is the third y axis entry (water) Set xVals = sht.Range(sht.Range("B2"), sht.Cells(Rows.Count, "B").End(xlUp)) Set yVals = xVals.Offset(0, 5) Set s = cht.SeriesCollection.NewSeries s.XValues = xVals s.Values = yVals With s.Format.Fill .Visible = msoTrue .ForeColor.RGB = RGB(0, 176, 240) .Transparency = 0 .Solid End With With s.Format.Line .Visible = msoTrue .ForeColor.RGB = RGB(0, 176, 240) .Transparency = 0 End With 'end Y axis entries cht.HasLegend = True 'below applies the legend names to be whatever are in parenthesis' cht.Legend.Select ActiveChart.SeriesCollection(1).Name = "Oil (BO)" ActiveChart.SeriesCollection(2).Name = "Gas (MCF)" ActiveChart.SeriesCollection(3).Name = "Water (BW)" 'below applies the data labels cht.SeriesCollection(1).Select cht.SeriesCollection(1).ApplyDataLabels cht.SeriesCollection(2).Select cht.SeriesCollection(2).ApplyDataLabels cht.SeriesCollection(3).Select cht.SeriesCollection(3).ApplyDataLabels 'below orients the datalabels to either above,below,right,or left cht.SeriesCollection(1).Select ActiveChart.SeriesCollection(1).DataLabels.Select Selection.Position = xlLabelPositionRight cht.SeriesCollection(2).Select ActiveChart.SeriesCollection(2).DataLabels.Select Selection.Position = xlLabelPositionAbove cht.SeriesCollection(3).Select ActiveChart.SeriesCollection(3).DataLabels.Select Selection.Position = xlLabelPositionLeft 'below moves the chart Dim iChart As Long Dim lTop As Double lTop = ActiveSheet.Range("Q10").Top For iChart = 1 To ActiveSheet.ChartObjects.Count ActiveSheet.ChartObjects(iChart).Top = lTop ActiveSheet.ChartObjects(iChart).Left = ActiveSheet.Range("Q1").Left lTop = lTop + ActiveSheet.ChartObjects(iChart).Height + ActiveSheet.Range("5:7").Height Next 'below deals with the chart title cht.SetElement (msoElementChartTitleAboveChart) With cht.ChartTitle .Text = sht.Name & Chr(10) & "Oil,Gas, and Water Production Through Well Life " .Characters.Font.Size = 12 End With 'below adds a filter to one column. You cannot have more than 1 filter per sheet. Columns("L:L").Select Selection.AutoFilter End If Next ws End Sub 

下面是一张照片,显示我的意思。 你可以在红色系列中明显地看到它,但是它也出现在绿色和蓝色系列中。

坏的填写图表

我相信你需要在系列上设置MarkerBackgroundColor

 s.MarkerBackgroundColor = RGB(255, 0, 0)