Charts Excel VBA-如何设置图表系列的线条样式?

Charts Excel VBA-如何设置图表系列的线条样式?,charts,excel,vba,Charts,Excel,Vba,根据用户指定的特定标准,我希望图表中的绘图线为实心、圆点或方点。我可以使用宏成功设置打印的线颜色和标记样式,但似乎找不到保存“打印线样式”属性值的对象。我尝试过使用record宏函数,但更改“属性”窗口中的线条样式不会显示在代码中,并且运行recorded宏没有任何效果 非常感谢您的帮助 YourChartSeries.Border.LineStyle = [some value from the XlLineStyle enumeration] 更新:在XL 2010中录制我得到了这个- A

根据用户指定的特定标准,我希望图表中的绘图线为实心、圆点或方点。我可以使用宏成功设置打印的线颜色和标记样式,但似乎找不到保存“打印线样式”属性值的对象。我尝试过使用record宏函数,但更改“属性”窗口中的线条样式不会显示在代码中,并且运行recorded宏没有任何效果

非常感谢您的帮助

YourChartSeries.Border.LineStyle = [some value from the XlLineStyle enumeration]
更新:在XL 2010中录制我得到了这个-

ActiveChart.SeriesCollection(1).Select
With Selection.Format.Line
    .Visible = msoTrue
    .DashStyle = msoLineSysDot
End With
ActiveChart.SeriesCollection(2).Select
With Selection.Format.Line
    .Visible = msoTrue
    .DashStyle = msoLineSysDash
End With

这可能就是您要查找的内容。

创建包含255个数据系列的图表,运行代码(并根据需要执行其他格式设置)。然后将其另存为模板

Sub dd()

Dim wb As Workbook
Set wb = Application.ActiveWorkbook

Dim myChart As Chart
Set myChart = wb.Charts("Chart5")

Dim mySeries As series

For Each mySeries In myChart.SeriesCollection
    mySeries.Format.Line.Weight = 1#
Next

End Sub

如果你有一个折线图,我最终创建了一个switch语句,因为我不知道如何创建一个“Name”变量数组。看


我尝试在excel中手动设置线条样式,并使用MsgBox(CurrentChart.SeriesCollection(1).Border.LineStyle),无论线条是方点、圆点、虚线等,它都返回-4105的值。您的问题令人困惑-您是问连接标记的线条,还是标记本身?请使用您拥有的任何代码更新您的问题:这总是有助于获得有用的答案。如果您手动右键单击打印的序列,然后单击“线样式”下的“格式化数据序列…”,则可以更改短划线类型。我希望能够将程序中的数据系列行格式化为“圆点”和“方点”。但是,XLineStyle枚举不提供这些短划线选项。此后,我决定放弃“方点”和“圆点”样式,改用XlContinuous、XlDot和XlDash。它不像正方形和圆形的圆点那么漂亮,但它确实起到了作用。
For j = i To num_lines_to_plot
        count = count + 1
        ActiveChart.SeriesCollection.NewSeries
        With ActiveChart.SeriesCollection(j)
            .Name = _
                "='"**... (you'll need to fill this in)**
            'create gradient
            .Format.Line.ForeColor.RGB = RGB(255, 20 * count, 0)
            'modify linetype
            If count > 4 Then
                line_type = count Mod 4
            Else
                line_type = count
            End If

            Select Case line_type
                Case Is = 1
                    .Format.Line.DashStyle = msoLineSolid
                Case Is = 2
                    .Format.Line.DashStyle = msoLineSquareDot
                Case Is = 3
                    .Format.Line.DashStyle = msoLineDash
                Case Is = 4
                    .Format.Line.DashStyle = msoLineLongDash
                End Select

        End With
    Next