诸位大侠好,我是菜鸟啊,急求大家帮助:
我借助已经生成的EXCEL表格中的数据绘制若干曲线图,下面是我以第3和第9列数据绘制了一副曲线图,代码如下,调试成功的。
Charts.Add
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("F6")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R2C3:R65500C3"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!R2C9:R65500C9"
ActiveChart.SeriesCollection(1).Name = "=""Figure08""" 'Figure08
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
ActiveChart.Legend.Select
Selection.Delete
With ActiveChart
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Speed [km/h]"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Average Acceleration [m/s/s]"
End With
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
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.ChartArea.Select
然后,我设置了关闭按钮,想关闭这副图形,于是写了如下代码:
ActiveSheet.ChartObjects("图表 8").Activate
ActiveChart.ChartArea.Select
ActiveWindow.Visible = False
Selection.Delete
结果程序总是报告出错啊:
实时错误‘1004’:
不能取得类 worksheet 的 chartobject 属性
以前好像运行是可以的啊,这到底是什么原因啊?如何解决啊?非常感谢高手的指点!!!! |