我试图在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
请帮。
删除这两行:
.HasErrorBars = True
.ErrorBars.Select
最后,虽然有点粗糙,但有一个解决问题的方法。
在图表中创建了两个相似的系列集合,并在其中一个上应用水平误差条图,在另一个上应用垂直误差条图。代码如下:
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