Like I said in comments, this is a very old problem which can be only sorted (I hope I am wrong) by activating the source sheet and selecting the chart. If you do not do that, you will end up with The specified dimension is not valid for the current chart type Chart.
error
Is this what you are trying?
Sub moveAllCharts(source As String, destination As String)
Dim chartObject As Object
ActiveWorkbook.Worksheets.Add(After:=Application.Worksheets(source)).Name = destination
For Each chartObject In Worksheets(source).ChartObjects
'~~> Need both of these
Worksheets(source).Activate
chartObject.Select
ActiveChart.Location xlLocationAsObject, destination
Next chartObject
End Sub
BTW, since you are forced to use .Activate
and .Select
, the above code should also include error handling. For example
Sub moveAllCharts(source As String, destination As String)
Dim chartObject As Object
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet: Set ws = wb.Worksheets(source)
On Error GoTo Whoa
wb.Worksheets.Add(After:=wb.Worksheets(source)).Name = destination
For Each chartObject In ws.ChartObjects
'~~> Need both of these
ws.Activate
chartObject.Select
ActiveChart.Location xlLocationAsObject, destination
Next chartObject
LetsContinue:
Exit Sub
Whoa:
MsgBox err.Description
Resume LetsContinue
End Sub
In Action
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…