2012-01-09 325 views
2

我想根据用户指定的某个标准,将图表中的图线设为实线,圆点或方点。我可以使用宏成功设置绘图的线条颜色和标记样式,但似乎无法找到保存绘图线条样式属性值的对象。我曾尝试使用记录宏函数,但在代码中未显示属性窗口中的线条样式,并且运行记录的宏没有效果。Excel VBA - 你如何为图表系列设置线条样式?

任何帮助,非常感谢!

回答

2
YourChartSeries.Border.LineStyle = [some value from the XlLineStyle enumeration] 

UPDATE:记录在2010 XL我得到这个 -

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 

这可能是你在找什么。

+0

我试图手动设置线条样式在Excel和使用 MSGBOX(CurrentChart.SeriesCollection(1).Border.LineStyle) 它返回一个-4105值,而不管如果行是正方形点,圆点,虚线等。 – user1130306 2012-01-09 18:39:46

+0

你的疑问很混乱 - 你问的是连接标记的线条还是标记本身?请使用您拥有的任何代码更新您的问题:这总能帮助您获得有用的答案。 – 2012-01-09 19:32:00

+0

如果手动右键单击绘制的系列并在“线型”下单击“格式化数据系列...”,则可以更改短划线类型。我希望能够将我的程序中的数据系列行格式化为“圆点”和“方形点”。但是XLineStyle枚举不提供这些破折号选项。 我后来决定取消“方形点”和“圆点”样式,并使用XlContinuous,XlDot和XlDash代替。它不像方形圆点那么漂亮,但它可以完成这项工作。 – user1130306 2012-01-09 21:25:02

3

用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 
0

如果你有一个折线图,我最终创建了一个switch语句,因为我无法弄清楚如何创建一个“Name”变量的数组。见list of line types here

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 
相关问题