Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To move a chart without receiving this error message, use either of the
following methods.
Method 1: Refer to the Chart as an Object
Assign an object variable to the chart object each time it is moved. You
must use this variable when you refer to the chart. For example, the
following macro creates an embedded chart on Sheet1 using data on Sheet1 in
the range A1:C4. The chart is moved to a new chart sheet and is then moved
back to Sheet1. In the following example, each time the chart object is
referenced, the variable X is set equal to the chart:
Sub MoveChart()
Dim x As Chart
' Create an embedded chart on a chart sheet.
Set x = Charts.Add
x.ChartType = xlColumnClustered
x.SetSourceData Source:=Sheets("Sheet1").Range("A1:C4")
Set x = x.Location(where:=xlLocationAsObject, Name:="Sheet1")
' Move chart to new sheet and reset the chart object variable x.
Set x = x.Location(where:=xlLocationAsNewSheet, Name:="Chart1")
' Move chart to back to the chart sheet.
Set x= x.Location(where:=xlLocationAsObject, Name:="Sheet1")
End Sub
Method 2: Refer to the Chart as ActiveChart
If it is not necessary to assign an object variable to the chart, refer to
the chart as ActiveChart. For example, the following macro statement uses
the
ActiveChart property and
Location method to move a chart
to a chart sheet named Chart1:
ActiveChart.Location where:=xlLocationAsNewSheet, Name:="Chart1"