【问题标题】:Read Chart Properties using VBA使用 VBA 读取图表属性
【发布时间】:2014-03-05 06:17:47
【问题描述】:

我正在使用 VBA 创建一些我需要做的图形。

基本上,我想做的是自动创建第一个系列,然后第二个系列复制第一个系列的颜色和格式。

我正在尝试执行此代码但没有成功:

ActiveChart.SeriesCollection(a - 1).Select
ActiveChart.SeriesCollection(a).Border.ColorIndex = ActiveChart.SeriesCollection(a - 1).Border.ColorIndex
ActiveChart.SeriesCollection(a).MarkerBackgroundColorIndex = ActiveChart.SeriesCollection(a - 1).MarkerBackgroundColorIndex
ActiveChart.SeriesCollection(a).MarkerForegroundColorIndex = ActiveChart.SeriesCollection(a - 1).MarkerForegroundColorIndex
ActiveChart.SeriesCollection(a).MarkerStyle = ActiveChart.SeriesCollection(a - 1).MarkerStyle

谁能帮助我了解如何阅读上一个系列的属性并将其应用于下一个系列?

谢谢。

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    一般来说这样的事情可以工作:

    Sub Tester()
        Dim Cht as Chart
        Dim a As Series, b As Series, x As Long
    
        Set cht = ActiveChart
        Set a = cht.SeriesCollection(1)
    
        For x = 2 To cht.SeriesCollection.Count
            Set b = cht.SeriesCollection(x)
            b.Border.Color = a.Border.Color
            b.MarkerBackgroundColor = a.MarkerBackgroundColor
            b.MarkerForegroundColor = a.MarkerForegroundColor
            b.MarkerStyle = a.MarkerStyle
        Next x
    
    End Sub
    

    但请注意,除非第一个系列被手动格式化,否则某些属性将不会被读取,而不仅仅是“默认”格式。

    例如:请参阅Fill and Border color property of data point marker (scatter or line) Excel VBA 了解类似问题。

    【讨论】:

      猜你喜欢
      • 2011-07-14
      • 2017-10-03
      • 2013-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多