2014-06-27 139 views
0

我只是想繪製一個簡單的系列圖,但是當我嘗試標記我的座標軸時,出現了一些奇怪的錯誤。我如何標記我的x,y軸?vba charting in excel 2010

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 

的錯誤是:對象變量或與塊變量未設置

+0

@PortlandRunner感謝,但沒有骰子。錯誤出現了.Axes(xlCategory,xlPrimary).HasTitle = True .........聲明 – user1681664

回答

2

這爲我工作,嘗試與其他內取出用塊:

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 
+0

謝謝。有效 – user1681664