Application-defined error or object defined error while copying chart using VBA

Occasional Visitor

Hi , 


Can you please help me figure out the problem I am facing with Word , VBA , Excel ? 


I am trying to copy a chart present in an Excel workbook into a Word document using VBA  macro , created in the Word doc ( Macro code is given below ) . 


The problem is that the macro gives following error : 


Run-time error 1004 :

Application defined or object defined error 


Now , if I simply open the excel workbook  , randomly click on some cells and save  it  (  note that no changes are done to the chart in question )  and re-run the  macro , then the problem goes away . 


I am unable to solve this problem . 


Macro code : ( Problem line is in bold ) 


Sub copy_chart()
' copy_chart Macro

Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True

Set wb = oExcel.Workbooks.Open(Application.ActiveDocument.Path & "\" & "Chart_copy_problem_1.xlsx", UpdateLinks:=False)

wb.WorkSheets("Regression results").ChartObjects("Cov_chart").Chart.ChartArea.Copy




End Sub























1 Reply


I am trying to figure out the same issue but for me it seems to not work when the chart is not in view (debug retry fails every time) and when I scroll down so I can see the chart and retry the debug, then it works. I'll keep investigating, I know this thread is old.