错误条在图表中不可见

时间:2016-09-26 09:24:08

标签: vba powerpoint errorbar

我正在尝试在MS Powerpoint的图表中创建水平和垂直误差线。虽然我可以使用VBA设置误差线的参数,但误差条不可见。当我手动检查图表中的错误栏设置时,将完成所需的设置。以下是我正在尝试的代码:

ActivePresentation.Slides(SlideNumb).Shapes(ChartName).Chart.Select
With ActivePresentation.Slides(SlideNumb).Shapes(ChartName).Chart.SeriesCollection(2)
    .HasErrorBars = True
    .ErrorBars.Select
    .ErrorBar Direction:=xlY, Include:=xlErrorBarIncludeBoth, Type:=xlErrorBarTypeCustom, Amount:=100, MinusValues:=100
    .ErrorBar Direction:=xlX, Include:=xlErrorBarIncludeBoth, Type:=xlErrorBarTypeCustom, Amount:=100, MinusValues:=100
End With
With ActivePresentation.Slides(SlideNumb).Shapes(ChartName).Chart.SeriesCollection(2).ErrorBars.Border
    .LineStyle = msoLineSingle   
    .Color = RGB(0, 112, 192)
    .Weight = 1.5
End With 
With ActivePresentation.Slides(SlideNumb).Shapes(ChartName).Chart.SeriesCollection(2).ErrorBars
     .Select
     .Format.Line.Visible = msoTrue
     .Format.Line.Style = msoLineSingle
     .Format.Line.Weight = 1.5
     .Format.Line.ForeColor.RGB = RGB(0, 112, 192)
     .Format.Line.DashStyle = msoLineSysDash
     .EndStyle = xlNoCap
End With

请帮忙。

2 个答案:

答案 0 :(得分:0)

删除这两行:

.HasErrorBars = True
.ErrorBars.Select

答案 1 :(得分:0)

最后,虽然有点粗糙,但解决了这个问题。

在图表中创建了两个相似的系列集合,并在第二个上应用了水平误差条图,在第二个上应用了垂直误差条图。以下是代码:

        ActivePresentation.Slides(SlideNumb).Shapes(ChartName).Chart.FullSeriesCollection(2).ErrorBar Direction:=xlY, Include:=xlBoth, Type:=xlFixedValue, Amount:=1000
        With ActivePresentation.Slides(SlideNumb).Shapes(ChartName).Chart.FullSeriesCollection(2).ErrorBars
            .EndStyle = xlCap
            With .Format.Line
                .Visible = msoTrue
                .DashStyle = msoLineDash
                .Weight = 2
                .ForeColor.ObjectThemeColor = msoThemeColorAccent1
            End With
        End With

        ActivePresentation.Slides(SlideNumb).Shapes(ChartName).Chart.FullSeriesCollection(3).ErrorBar Direction:=xlX, Include:=xlBoth, Type:=xlFixedValue, Amount:=1000
        With ActivePresentation.Slides(SlideNumb).Shapes(ChartName).Chart.FullSeriesCollection(3).ErrorBars
            .EndStyle = xlCap
            With .Format.Line
                .Visible = msoTrue
                .DashStyle = msoLineDash
                .Weight = 2
                .ForeColor.ObjectThemeColor = msoThemeColorAccent1
            End With
        End With