1
votes

This may seem trivial but I haven't been able to find a way. How do PowerPoint Object Model allow you to add a Shape object to a slide's Shapes collection? I can add new shapes using functions like Shapes.AddSmartArt(), Shapes.AddPicture() etc, but those will add new shapes. What if I have an existing Shape object's reference that I want to add to slide's shapes?

One way of doing it is to call Copy() on the shape object and then call Paste() in the target slide, but I find it less than ideal since we'll modify the clipboard in the process (I know we can restore it after the operation, but then again this is lame).

There are no Add(), Append() or Insert() functions in the Shapes collection as far as I have searched.

Edit

Perhaps I didn't make it clear enough. Let me try again. Say I have a Shape object in a variable like this (PowerPoint/VSTO/C#):

Shape s = GetShape(); //This function returns a Shape object
MyPresentation.Slides[1].Shapes.???(s);

I need a suitable function in place of ???; something like Add, Insert, Append etc, but nothing like this exists in the Object Model.

1
I don't really understand your problem: The way to move or copy a shape from one slide to an other slide is to copy it, paste it and delete the old if wanted . What means you modify the content of the clipboard? When you want to be successful you have keep the clipboard as it is. - Christine Ross
@ChristineRoss: See my edit. - dotNET
my answer remains copy and paste. You don't need your mysterious function getshape, because all kind of shape have a method for creation (shapes, charts,..). See here - Christine Ross

1 Answers

0
votes

Shape collections are read-only. That is because they contain only the shapes specific to a range. In Word, that range can be a paragraph, a section, a header, a group shape, the entire document, etc. In PowerPoint, I assume you can get a list of shapes from a slide, all slides, and maybe a group shape.

You can't add directly to a shapes collection because you would have have to specify where that shape is supposed to go. The methods for doing that with new shapes already exists. Such a method does not exist for moving or copying shapes.

It would be nice if there was a method to move a shape to a different location without using copy/paste, but someone at Microsoft must have decided that it wasn't worth doing.