我正在使用 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)行导致错误:“无法设置内部类的颜色属性”。我猜我不应该在 .Activechart 下调用 .SeriesCollection。有什么建议么?在这一点上,我很高兴能够将图表的背景颜色更改为白色,并将 x 轴标签旋转 45 度。
先感谢您。