Excel 将图表系列的颜色更改为与其他系列相同但具有不同线条样式的颜色
我试图做一个代码,改变一个系列的颜色,以匹配另一个系列,但不同的线型(如虚线)。请看我做的代码。我收到错误消息 多谢各位Excel 将图表系列的颜色更改为与其他系列相同但具有不同线条样式的颜色,excel,vba,excel-charts,Excel,Vba,Excel Charts,我试图做一个代码,改变一个系列的颜色,以匹配另一个系列,但不同的线型(如虚线)。请看我做的代码。我收到错误消息 多谢各位 Sub lineeditor() Dim j As Integer Dim wsheet As Worksheet Dim cht As ChartObject Dim serie As Series For Each wsheet In ThisWorkbook.Worksheets 'Looping through chart in every chartobjects
Sub lineeditor()
Dim j As Integer
Dim wsheet As Worksheet
Dim cht As ChartObject
Dim serie As Series
For Each wsheet In ThisWorkbook.Worksheets
'Looping through chart in every chartobjects
For Each cht In wsheet.ChartObjects
cht.Activate
cht.Select
'Looping through second set of 9 series. totally 18 series are in the chart
For j = 1 To 9
cht.Chart.SeriesCollection(j + 9).Select
With Selection.Format.Line
.ForeColor = cht.Chart.SeriesCollection(j).Format.Line.ForeColor
.DashStyle = msoLineDashDot
End With
Next
Next
Next
End Sub
不能选择不在ActiveSheet上的工作表对象。但是,应仅在绝对必要时选择或激活对象。手表:
“我得到错误消息”不是一个非常有用的描述当你运行你的代码时会发生什么。谢谢你的回答。序列位于同一图表/图表对象中。如果有人能帮我编写代码,使一个系列具有相同的颜色,而另一个系列具有不同的线型,我将不胜感激。
Sub lineeditor()
Dim j As Integer
Dim wsheet As Worksheet
Dim cht As ChartObject
Dim serie As Series
For Each wsheet In ThisWorkbook.Worksheets
For Each cht In wsheet.ChartObjects
For j = 1 To 9
With cht.Chart.SeriesCollection(j + 9).Format.Line
.ForeColor = cht.Chart.SeriesCollection(j).Format.Line.ForeColor
.DashStyle = msoLineDashDot
End With
Next
Next
Next
End Sub