运行宏时,我得到重复的粘贴图表。它的作用是浏览所有Excel工作表并复制可用的图表,然后将它们粘贴到ChartObjects页面上。
你看到错误吗?你能帮忙纠正吗?
Sub Test1()
Dim cht As Excel.ChartObject
Worksheets("ChartObjects").ChartObjects.Delete
For Each Sheet In ActiveWorkbook.Worksheets
If Sheet.Name <> "ChartObjects" Then
Sheet.Select
For Each cht In Sheet.ChartObjects
cht.Select
cht.Copy
Sheets("ChartObjects").Select
Range("C5").Select
ActiveSheet.Paste
Next
End If
Next Sheet
End Sub
答案 0 :(得分:2)
您需要从For Each循环中排除ChartObjects。
For Each Sheet In ActiveWorkbook.Worksheets
If Sheet.Name<>"ChartObjects" Then
'your code
End if
Next Sheet