VBA scenarios 1004: Application-defined or Object-defined scenarios when copying a chart to a new workbook
I'm wondering if anyone has experience with I'm performance testing and I'm working on a project and hit a roadblock... Does anyone know how to I tried several approaches but none seem to work... I'm trying to automate the process of copying a chart from one workbook to a new workbook in Excel using VBA, but I keep hitting a wall with a 'Run-time behavior 1004: Application-defined or Object-defined behavior'. The code I'm using is as follows: ```vba Sub CopyChartToNewWorkbook() Dim sourceWorkbook As Workbook Dim newWorkbook As Workbook Dim chartToCopy As ChartObject ' Set the source workbook Set sourceWorkbook = ThisWorkbook ' Reference the specific chart I want to copy Set chartToCopy = sourceWorkbook.Sheets(1).ChartObjects(1) ' Create a new workbook Set newWorkbook = Workbooks.Add ' Attempt to copy the chart chartToCopy.Copy ' Paste the chart into the new workbook newWorkbook.Sheets(1).PasteSpecial End Sub ``` I've confirmed that the chart is indeed present in the source workbook and that I'm referencing it correctly. However, when I run this code, it throws the aforementioned behavior at the line `newWorkbook.Sheets(1).PasteSpecial`. I've tried a few variations, like simplifying the paste method to just `newWorkbook.Sheets(1).Paste`, but I still get the same behavior. Could this be an scenario with how the new workbook is being created or the way I'm handling the chart object? I'm using Excel 2019, and I've ensured that macros are enabled. Any suggestions on what might be going wrong or how to properly copy a chart to a new workbook without working with this behavior? Itβs driving me crazy! For context: I'm using Vba on Ubuntu. I'm open to any suggestions. Any suggestions would be helpful. For reference, this is a production REST API. What are your experiences with this? I recently upgraded to Vba 3.9. Any ideas what could be causing this?