如何在VBA Excel中设置(或重置)线条粗细和强度?

时间:2017-06-26 16:32:17

标签: excel vba excel-vba

在以下代码中:

    For i = 1 To j
       ActiveChart.SeriesCollection(i).Select
       With Selection
           .MarkerStyle = xlNone
           .Smooth = False
           .MarkerSize = 2
           .Shadow = False
       End With
       With Selection.Border
           .Weight = 1
           .LineStyle = xlContinuous
           Select Case i
              Case 1 To 2
                   .ColorIndex = black
                   .Weight = 4
                   .LineStyle = xlDot
               Case 3
                   .ColorIndex = red
                   .Weight = 5
               Case 4
                   .ColorIndex = light_brown
                   .TintAndShade = 0.5
               Case 5
                   .ColorIndex = dark_blue
                   .TintAndShade = 0.5
               Case 6
                   .ColorIndex = solid_blue
                   .TintAndShade = 0.5
              Case 7
                   .ColorIndex = cyan
                   .TintAndShade = 0.5
              Case 8
                   .ColorIndex = bright_green  'purple
                   .Weight = 5
              Case 9
                   .ColorIndex = bright_green
                   .Weight = 5
              Case Else
                   .ColorIndex = black
                   .Weight = 2
           End Select
       End With
    Next i

它停在案例3 VBA并声称它“无法设置边框类的Weight属性” 如何根据自己的厚度和颜色强度制作不同的线条? 感谢

1 个答案:

答案 0 :(得分:0)

这对我有用。确保您拥有.Format.Line.Visible = msoTrue

With ActiveChart
    With .SeriesCollection(1)
        With .Format.Line
            .Visible = msoTrue
            .ForeColor.RGB = RGB(91, 155, 213)
        End With
        .Border.Weight = 2
    End With
    With .SeriesCollection(2)
        With .Format.Line
            .Visible = msoTrue
            .ForeColor.RGB = RGB(91, 155, 213)
        End With
        .Border.Weight = 3
    End With
    With .SeriesCollection(3)
        With .Format.Line
            .Visible = msoTrue
            .ForeColor.RGB = RGB(91, 155, 213)
        End With
        .Border.Weight = 4
    End With
End With