【问题标题】:Can't change Width of Custom ErrorBars无法更改自定义错误栏的宽度
【发布时间】: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 NextYourChartObject.ProtectFormatting = True,这仅在已经创建图表和误差线并且之后设置保护时类似于您的麻烦。也许更多信息会有所帮助。它们在创建后是否发生了变化?您可以在您的潜艇运行后手动更改重量吗?如果您单步执行它并在本地窗口中观察 eB 对象,它会在那里发生变化吗?
  • 我最终删除了我的代码并在没有任何 With 语句(或限制它们)的情况下重新编写。似乎有效,但我认为问题不在于 Series 和 ErrorBars 对象都具有 Weight 属性。

标签: excel charts vba


【解决方案1】:

我认为问题出在.HasErrorBars = True 上,如果不存在错误栏,它已经自动创建了一个错误栏,而下一行.ErrorBar 会创建另一个错误栏。

此时您有两个错误栏,在我的情况下,.Format.Line.Weight = 12 只影响了第一个自动添加的错误栏。

在使用.ErrorBar 之前尝试设置.HasErrorBars = False,看看是否有不同。

.HasErrorBars = False
.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 

*要尝试的另一件事是在更改刷新后切换.Format.Line.Visible

【讨论】:

    【解决方案2】:

    根据 Microsoft 文档,您需要使用“重量”:

    ErrorBars --> 边框:https://msdn.microsoft.com/en-us/library/aa174210%28v=office.11%29.aspx

    边框 --> 权重:https://msdn.microsoft.com/en-us/library/aa215968%28v=office.11%29.aspx

    【讨论】:

    • 你能告诉我为什么是-2吗?有人提到了官方文档,我用它来解释为什么使用重量......??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 2018-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多