Method 'Sheets' of object '_Global' failed

I'm using Powerpoint 2000.
I have inserted and excel chart into a slide as an excel chart object. I want to update the source data range that the chart is using when data is added to the sheet.

I'm getting this error: Method 'Sheets' of object '_Global' failed
I've been trying some variations of the code below.
'ActivePresentation.Slides("Excess Package Percentage").Shapes("Excess Pkg").OLEFormat.Object.Charts("Excess Pkg Chart").SetSourceData Source:=Sheets("Excess Pkg Sheet").Range("A2:D99"), PlotBy:=xlColumns

Open in new window

Who is Participating?
Rory ArchibaldConnect With a Mentor Commented:
If the sheet is in the same embedded workbook, then you can use:

With ActivePresentation.Slides("Excess Package Percentage").Shapes("Excess Pkg").OLEFormat.Object
   .Charts("Excess Pkg Chart").SetSourceData Source:=.Sheets("Excess Pkg Sheet").Range("A2:D99"), PlotBy:=2
End With

Open in new window

Patrick MatthewsConnect With a Mentor Commented:
Hello coperations07,

Assuming this is running from PowerPoint, you should qualify the reference to the Sheets collection with
whatever variable you used to instantiate the Excel.Application object:

ActivePresentation.Slides("Excess Package Percentage").Shapes("Excess Pkg").OLEFormat.Object.Charts("Excess Pkg Chart").SetSourceData _
    Source:=xlApp.Sheets("Excess Pkg Sheet").Range("A2:D99"), PlotBy:=xlColumns

Also, if you are going to use named constants from the Excel library, such as xlColumns, you need to either
declare them in your code, or use early binding.


coperations07Author Commented:
Thanks guys!

rorya's code is working perfectly for me. I'm still trying to figure out exactly how/when to use the With Blocks.
And thank you patrick for the good information.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.