【发布时间】:2015-04-26 23:00:59
【问题描述】:
我正在尝试通过 Excel VBA 在图表中创建 ErrorBars,但我需要宽度为 12PT 或变化。这是我正在使用的代码,但它看起来不像在工作:
Set s = .SeriesCollection.NewSeries()
With s
.Name = "=GraphicSchedule!$" & getColumn(objList.ListColumns.Item("Activity").Range.Column) & "$" & sourceRow
.XValues = "=GraphicSchedule!$" & getColumn(objList.ListColumns.Item("DateMid").Range.Column) & "$" & sourceRow
.Values = "=GraphicSchedule!$" & getColumn(objList.ListColumns.Item("Loc1").Range.Column) & "$" & sourceRow
.HasErrorBars = True
.ErrorBar Direction:=xlX, Include:=xlErrorBarIncludeBoth, Type:=xlErrorBarTypeCustom, Amount:="=GraphicSchedule!$" & getColumn(objList.ListColumns.Item("BarLength").Range.Column) & "$" & sourceRow, MinusValues:="=GraphicSchedule!$" & getColumn(objList.ListColumns.Item("BarLength").Range.Column) & "$" & sourceRow
Set eB = .ErrorBars
With eB
With .Format.Line
.Visible = msoTrue
.Style = msoLineSingle
.Weight = 12
End With
.EndStyle = xlNoCap
End With
.HasDataLabels = True
Set dLabels = .DataLabels
With dLabels
.Format.TextFrame2.TextRange.InsertChartField msoChartFieldRange, "=GraphicSchedule!$" & getColumn(objList.ListColumns.Item("Activity").Range.Column) & "$" & sourceRow
.ShowRange = True
.ShowSeriesName = False
.ShowValue = False
End With
End With
我认为使用 Weight 属性会起作用,但我是否忽略了什么?
【问题讨论】:
-
我在 2010 年工作得很好。你看到了什么?
-
误差条宽度是否适合您?对我来说,它只在 4 点左右显示。
-
是的。 2016 年也是如此。
-
我可以复制的唯一方法是使用
On Error Resume Next和YourChartObject.ProtectFormatting = True,这仅在已经创建图表和误差线并且之后设置保护时类似于您的麻烦。也许更多信息会有所帮助。它们在创建后是否发生了变化?您可以在您的潜艇运行后手动更改重量吗?如果您单步执行它并在本地窗口中观察 eB 对象,它会在那里发生变化吗? -
我最终删除了我的代码并在没有任何 With 语句(或限制它们)的情况下重新编写。似乎有效,但我认为问题不在于 Series 和 ErrorBars 对象都具有 Weight 属性。