When you try to copy a chart in VBA, you may suddenly encounter the error:
“Run-time error -2147221040 (800401d0): Copy method of ChartObject class failed.”
This error can be confusing and difficult for VBA beginners to handle.
In this article, I will explain the following points step by step:
- The meaning of the error
- Common causes
- Practical solutions
Error Meaning: What is “Copy Method Failed”?
This error indicates that Excel failed to perform the copy operation when you tried to execute ChartObject.Copy in VBA.
Internally, this often happens when the code tries to use .Copy while the “ActiveWindow” does not exist, or the “ActiveSheet” is not correctly specified.
Main Causes
| Cause | Detailed Explanation |
| Target sheet is inactive | If the sheet containing the chart is not active, .Copy may fail. |
| Chart is not selected | Excel may not be able to process the copy operation correctly if the chart is not active (selected). |
| Excel window is minimized/hidden | Since .Copy depends on the visible state of the window, it may not work if Excel is inactive or minimized. |
| It is a Chart Sheet, not a ChartObject | ChartObject applies to embedded charts. Standalone Chart Sheets are not supported by this method. |
Solutions
Method 1: Activate the Sheet Containing the Chart First
srcChartObj.Parent.Activate ' Activate the parent sheet of the chart
srcChartObj.Copy
By explicitly activating the sheet, you ensure that Excel can process the .Copy command correctly.
Method 2: Use PasteSpecial or Paste for Stability
Worksheets("Output").Activate
Worksheets("Output").Range("B16").Select
ActiveSheet.Paste
Calling Paste on the active destination immediately after ChartObject.Copy improves the stability of the paste process.
Method 3: Replicate as an Object Instead of an Image
If you want to copy the chart data rather than just the image, you can manage the Chart object directly.
Dim newChart As ChartObject
Set newChart = Worksheets("Output").ChartObjects.Add(Left:=100, Top:=100, Width:=400, Height:=300)
newChart.Chart = srcChartObj.Chart
There is also a method to copy chart content via .Chart. This allows for stable replication without using .Copy and the clipboard.
Summary
The most important point about “Run-time error -2147221040” is that it depends heavily on the active state and display state of the sheet where the chart is located.
In VBA, you can avoid many stability issues by following steps such as “activate the copy source once” and “explicitly select the paste destination.”
