excel 2010中的vba图表制作

excel 2010中的vba图表制作,vba,excel,Vba,Excel,我只是想画一个简单的序列图,但当我尝试标记轴时,我会出现一些奇怪的错误。如何标记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

我只是想画一个简单的序列图,但当我尝试标记轴时,我会出现一些奇怪的错误。如何标记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

错误是:对象变量或with block variable not set(未设置with block变量)

这对我有效,请尝试用以下方法删除另一个with块中的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

@谢谢,但不要掷骰子。.Axes(xlCategory,xlPrimary).hasttle=True………语句出现错误