0

VBScript を使用して、Excel 2003 のデータの列から折れ線散布図を作成しています。問題なく表示されますが、背景色や軸ラベルなど、グラフのプロパティの一部を編集したいと考えています。これを Excel で手動で行い、マクロを記録すると、次の VBA コードが得られました。

ActiveChart.PlotArea.Select
With Selection.Border
    .ColorIndex = 16
    .Weight = xlThin
    .LineStyle = xlContinuous
End With
With Selection.Interior
    .ColorIndex = 2
    .PatternColorIndex = 1
    .Pattern = xlSolid
End With
ActiveChart.Axes(xlCategory).Select
With Selection.TickLabels
    .ReadingOrder = xlContext
    .Orientation = 45
End With
ActiveChart.Axes(xlValue).AxisTitle.Select
With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
    .ReadingOrder = xlContext
    .Orientation = xlHorizontal
End With
ActiveChart.ChartArea.Select
End Sub

これは VBA では問題ないように見えますが、VBScript への変換に問題があります。どのように始めればよいですか?これは現時点での私のコードです:

Set objChart = objExcel.Charts.Add()
With objExcel.ActiveChart
    .ChartType = xlXYScatterLinesNoMarkers
    .SeriesCollection(1).Interior.Color = RGB(255, 0, 0)
    .HasTitle = True
    .ChartTitle.Text = "usage"
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time"
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "units"
    .HasLegend = False
    .SetSourceData objWorksheet.Range("E1","F" & LastRow), xlColumns
    .SetSourceData objWorksheet.Range("E1:F200"), xlColumns
End With

.SeriesCollection(1).Interior.Color = RGB(255, 0, 0)により、「Interior クラスの色プロパティを設定できません」というエラーが発生します。.Activechart のすぐ下で .SeriesCollection を呼び出すべきではないと思います。助言がありますか?この時点で、グラフの背景色を白に変更し、x 軸のラベルを 45 度回転させることができれば幸いです。

前もって感謝します。

4

3 に答える 3

0

次の 2 つのことがあります。

  1. プロット領域を特定の色に設定する

例を見る

'set plotting area to dark gray color
ActiveChart.PlotArea.Select
With Selection.Format.Fill
    .Visible = msoTrue
    .ForeColor.ObjectThemeColor = msoThemeColorBackground1
    .ForeColor.TintAndShade = 0
    .ForeColor.Brightness = -0.5
    .Solid
End With

.ForeColor.ObjectThemeColor = msoThemeColorBackground1

  1. チャートの一般的な領域を特定の色に設定します(プロット領域を除くチャートの領域全体を意味します)

    'グラフ エリアの色をグレーに設定 With ActiveSheet.Shapes("NameChart").Fill .Visible = msoTrue .ForeColor.ObjectThemeColor = msoThemeColorBackground1 .ForeColor.TintAndShade = 0 .ForeColor.Brightness = -0.5 .Solid End With

Chart を生成するときに、VBA コードで Chart の名前が「NameChart」として設定されている場合

  'set the name of the Chart to "Cooper" to reference it later
ActiveChart.Parent.Name = "NameChart"

.ForeColor.ObjectThemeColor = msoThemeColorBackground1

私の答えが何らかの形で役に立った場合は、評価してください。ありがとう。

于 2016-03-07T08:57:52.917 に答える
0

順序が重要です。シリーズにアクセスするには、まずシリーズを追加する必要があります。などの他のプロパティについても同様HasTitleです。また、XY ダイアグラムの線には内部の色がなく、内部を示すグラフ (円グラフや縦棒グラフなど) でのみ使用できます。おそらくここで境界線の色を意味します。コードを次のように変更します。

Set objChart = objExcel.Charts.Add
With objChart
  ' define chart type
  .ChartType = xlXYScatterLinesNoMarkers

  ' define data
  .SetSourceData objWorksheet.Range("E1:F200"), xlColumns

  ' format chart
  .SeriesCollection(1).Border.Color = RGB(255, 0, 0)
  .PlotArea.Interior.Color = RGB(255, 255, 255)
  '.PlotArea.Interior.ColorIndex = 2  'alternative
  .HasTitle = True
  .ChartTitle.Text = "usage"
  .Axes(xlCategory, xlPrimary).HasTitle = True
  .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time"
  .Axes(xlValue, xlPrimary).HasTitle = True
  .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "units"
  .HasLegend = False
End With

シンボリック定数を定義していれば、機能するはずです。

于 2013-07-17T20:58:58.690 に答える