2016-09-13 11 views
0

vb6を使用してExcelチャートを作成しようとしています。アレイにフィードをしようとすると、エクセルの範囲を与える代わりに。そして、私はエラーを取得しています。 これは配列を使用してVBAチャートを作成する

Private Sub CreateChart(Optional ByVal ChartTitle As String _ 
       , Optional ByVal xAxis As Excel.Range _ 
       , Optional ByVal yAxis As Excel.Range _ 
       , Optional ByVal ColumnName As String _ 
       , Optional ByVal LegendPosition As XlLegendPosition = xlLegendPositionRight _ 
       , Optional ByVal rowIndex As Long = 2 _ 
       , Optional ByRef ChartType As String = xlLineMarkers _ 
       , Optional ByVal PlotAreaColorIndex As Long = 2 _ 
       , Optional ByVal isSetLegend As Boolean = False _ 
       , Optional ByVal isSetLegendStyle As Boolean = False _ 
       , Optional ByVal LegendStyleValue As Long = 1) 

Const constChartLeft = 64 
Const constChartHeight = 300 
Const constChartWidth = 700 

Dim xlChart As Excel.ChartObject 
Dim seriesCount As Long 
Dim ColorIndex As Long 

Dim j As Long 


With mWorksheet 
    .Rows(rowIndex).RowHeight = constChartHeight 

    Set xlChart = .ChartObjects.Add(.Rows(rowIndex).Left, .Rows(2).Top, constChartWidth, constChartHeight) 
End With 

With xlChart.chart 
    .ChartType = ChartType 
    .SetSourceData Source:=marrayPOClient, PlotBy:=marrayPOSKU 
    .SeriesCollection(1).XValues = marrayPOClient 
    .HasTitle = True 

    .Legend.Position = LegendPosition 
    .Legend.Font.Size = 7.3 
    .Legend.Font.Bold = True 
    .Legend.Border.LineStyle = xlNone 

    .ChartTitle.Characters.Text = ChartTitle 
    .ChartTitle.Font.Bold = True 

    .Axes(xlValue).TickLabels.Font.Size = 8 ' yAxis Labels 
    .Axes(xlCategory).TickLabels.Font.Size = 8 ' xAxis Labels 

    .PlotArea.Interior.ColorIndex = PlotAreaColorIndex 
    .PlotArea.Interior.ColorIndex = 15 
    .PlotArea.Interior.PatternColorIndex = 1 
    .PlotArea.Interior.Pattern = xlSolid 
End With 
End Sub 

に取り組んでイムコードです、それはチャートの配列を使用することが可能です。可能であれば私の間違いは何ですか?

+0

*私はエラーを取得しています* - あなたが得ているエラーを正確に教えてくれると便利です。 –

+0

@ Mat'sMugそれは "オブジェクトが必要です"と言います –

+0

いいです、それは始まりです...コード行や特定の関数呼び出しが強調表示されますか? –

答えて

1

マットのマグカップが言うように、SetSourceDataRangeを必要としていますが、これはなく、新しいシリーズを作成します

.SeriesCollection.NewSeries 
.SeriesCollection(1).Values = marrayPOClient 

.SetSourceData Source:=marrayPOClient, PlotBy:=marrayPOSKU 

を交換して、別の方法

を使用して結果を得ることができます配列を一連の値として代入する

0

Chart.SetSourceDataSourceパラメータのRangeオブジェクト、及びそのPlotByパラメータの​​列挙値を必要とします。

は、それらの名前が宣言されているとそれらがどのように割り当てられている場所を示していない(暗示するので、我々は彼らのタイプまたは値を知ることができないようmarrayPOClientmarrayPOSKU両方が配列あるIを想定しています)、最初のパラメーターにはRange、2番目のパラメーターにはxlColumnsまたはxlRowsのいずれかを指定する必要があります。

+0

それも私が思ったものです。それを行う他の方法はありますか?私は 'chart.values'を使ってみましたが、それでも失敗しました。エラーは "Invalid Parameter"と表示されます –

関連する問題