0

I have seen many answers out here and there that suggest to use the Copy() and Paste() methods for copying shapes between slides, presentations and applications:

These methods work fine but have side effects because they interact with the clipboard without user consent. When a program runs a series of copy-paste operations in background, it is impossible for a user to work with the clipboard.

I have been looking for a possibility to backup and restore the clipboard, but it looks like it is a wrong way (see these answers). Another reason for not using the clipboard for copying is that if a user copies something into clipboard just before we call Paste() we will end up with a wrong result.

Is there a sane way?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
utapyngo
  • 6,946
  • 3
  • 44
  • 65

1 Answers1

1

You could conceivably use the .Export method on the shape to export it as, say, EMF, then insert it as a picture into the target slide. That won't give you the same result as copy/pasting the shape, though.

I wouldn't worry all that much about the user copying something in between your programmatic copy/paste. Even if PPT were to allow that (which I'm not sure it would) your copy/paste operation would be almost instantaneous.

That still leaves the problem of not deleting whatever else the user might have put on the clipboard. Office maintains its own clipboard independent of the Windows system clipboard, but other than one comment, I couldn't find anything on how you could programmatically control it. And that one comment, from a source I trust, said that you can't, at least not in Office versions later than 2000. But it's something you might want to look further into.

Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34
  • there is no .Export method on the shape object. – chipbk10 Sep 25 '14 at 14:23
  • 1
    There is. You have to into the object browser (press F2 in the IDE) then rightclick anywhere IN the object browser and choose Show Hidden Members. Then intellisense will show you the .Export method for shapes. – Steve Rindsberg Sep 26 '14 at 14:59
  • There is no "Show Hidden Members" in the object browser. Please take a look at my screen shot https://www.dropbox.com/s/4x8vnpk29l6u6sv/screenshot.png?dl=0 – chipbk10 Sep 29 '14 at 08:39
  • I found an option in Object Browser to show hidden types and members. However, the Visual Studio does not show me the .Export method. – chipbk10 Sep 29 '14 at 08:49
  • In that case, you may have to resort to deviousness. Note the dimensions of the shape you want to export. Add a new (optionally hidden) presentation and set its dimensions to match the shape, then copy/paste the shape into the new presentation and use the Slide.Export method to save as a graphic. But that brings us back to the clipboard problem, so it may not do. – Steve Rindsberg Sep 29 '14 at 14:30