2016-05-31 59 views
0

我編寫VBA代碼,圖表工作表中每個工作表當前工作表如何圖表使用VBA

Sub InsertChartsAfterWorksheets() 
Dim myWorksheet As Worksheet 
Dim myChart As Chart 

For Each myWorksheet In Worksheets 
Set myChart = Charts.Add 
myChart.ChartType = xlXYScatterLines 

myChart.Move After:=myWorksheet 
Next myWorksheet 
End Sub 

右後和它出錯的圖表,錯誤的東西,我需要改變???

+1

你說的意思 「出了問題......」? –

+0

它所有相同的圖表 –

回答

2

請閱讀我的問題評論...

我猜你希望每個工作表後添加圖表(顯示爲一個表)。

Dim wbk As Workbook 
Dim wsh As Worksheet 
Dim chrt As Chart 

Set wbk = ThisWorkbook 
For each wsh in wbk.Worksheets 
    Set chrt = wbk.Charts.Add(After:=wsh) 
    With chrt 
     'change some properties of chart 
    End With 
Next 

如需進一步信息,請訪問:
Charts.Add method
Creating Charts in Excel 2003 Using Visual Basic for Applications Code