2015-04-26 49 views
6

我想通過Excel VBA在圖表中創建錯誤條,但是我需要寬度爲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 

我想通使用權性質的工作,但沒有我忽略的東西嗎?

+0

2010年適合我。你看到了什麼? – Rory

+0

錯誤欄寬度是否爲12pt?這只是在4點左右對我來說。 – jDave1984

+0

是的,是的。同樣在2016年。 – Rory

回答

2

我認爲這個問題是.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

相關問題