2010年excel中的vba图表

时间:2014-06-27 00:45:12

标签: excel vba excel-vba

我只是试图绘制一个简单的系列,但是当我尝试标记我的轴时,我得到了一些奇怪的错误。如何标记x,y轴?

With ActiveSheet.ChartObjects.Add(Left:=10, Width:=875, Top:=75, Height:=425)
    .Chart.SetSourceData Source:=ws.Range("A1:B" & rows)
    .Chart.ChartType = xlLine
        With ActiveChart
            .Axes(xlCategory, xlPrimary).HasTitle = True
            .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time"
            .Axes(xlValue, xlPrimary).HasTitle = True
            .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Price"
        End With
End With

错误是:对象变量或未设置块变量

1 个答案:

答案 0 :(得分:2)

这对我有用,尝试用另一个删除with块:

ActiveSheet.Shapes.AddChart(Left:=10, Width:=875, Top:=75, Height:=425).Select

With ActiveChart
    .SetSourceData Source:=ws.Range("A1:B" & rows)
    .ChartType = xlLine
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Text = "Time"
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Price"
End With