Keenlearner
Keenlearner

Reputation: 704

Subscript out of range when copying charts from excel to word

Hi i'm facing a subscript out of range error when I tried to copy a chart from excel sheet to word document. I checked the worksheet name it seems to be fine. I tried changing to ThisWorkbook.Sheets(wsname) but i received an application define type error. How do I go about resolving this issue.

With ThisWorkbook.Worksheets(wsName)
   .ChartObjects(1).Activate
   ActiveChart.ChartArea.Copy
End With

The name of the worksheet I'm trying to reference

enter image description here

Upvotes: 1

Views: 290

Answers (1)

Keenlearner
Keenlearner

Reputation: 704

I have finally figured out what's the problem.

Since I'm referencing a chartsheet and not a worksheet, I have to use .Charts instead of .Worksheets. In addition since it is a chartsheet, the chartsheet itself is a chart object, hence .ChartObjects(1) is not required, only .ChartArea.Copy

Correct Code:

With ThisWorkbook.Charts(wsName)
  .ChartArea.Copy
End With

Upvotes: 2

Related Questions