programmatically pasting an embedded excel chart ino powerpoint RRS feed

  • Question

  • I have a linked Excel chart in one PowerPoint slide that I want to copy and paste over to another slide, except I want the pasted version to be embedded in PowerPoint rather than linked. This works fine when I do it manually, as long as the original excel file is open--I simply copy the chart in PowerPoint, go to the next slide, paste, then click on the lower right corner and change from "Chart (linked to Excel data) to "Excel Chart (entire workbook)." I need to be able to do this programmatically, though, so I can do it quickly for 50 slides.

    Here's the code I have right now, where Shapes(1) is an excel chart:

    Sub copyPaste()
      ActivePresentation.Slides(2).Shapes.PasteSpecial ppPasteOLEObject, msoFalse
    End Sub 

    I run into the following error when I run it, on line 3: "Run-time error '-2147188160 (80048240)': Shape (unknown member): Invalid request. To select a shape, its view must be active."

    I don't get this error when I do most other pastespecial options (ppPastebitmap, ppPastemetafilepicutre, etc...), or with regular paste. When I do regular paste, I just get another linked chart. Note: I am running Office 2007 on Windows XP.

    Something like this would do the trick (http://www.pptfaq.com/FAQ00935.htm), except that it only works on PowerPoint 2003.

    Thanks so much for any help or advice you can give me!

    Wednesday, April 13, 2011 4:26 PM

All replies

  • Omit the line that selects the shape in the first slide. If you can reference it (which you can, using "ActivePresentation.Slides(1).Shapes(1)"), there's no need to select it.

    Jon Peltier, Microsoft Excel MVP
    Peltier Technical Services, Inc.
    Peltier Tech Blog

    Saturday, April 16, 2011 9:52 PM