Stephen Watkins
Stephen Watkins

Reputation: 25775

How to copy picture from Word to Powerpoint programmatically?

I am creating a macro that converts a Word 2007 document into a structured PowerPoint 2007 presentation. I am looping over all the paragraphs of the document and copying them over to the new presentation.

I am able to copy and paste the paragraphs to the presentation just fine. But I also need to be able to copy and paste the pictures from the Word document into the PowerPoint (and in the right location between paragraphs).

So far, I am able to detect if a paragraph is a picture by looking at the paragraph's style attribute - it will say "Figure". But, I don't know what to do from there. After looking online, it looks like I should be able to do this:

paragraphFromDocument.Range.Copy
currentSlide.Shapes.Paste

But, this doesn't seem to work. How do I copy a picture from Word to PowerPoint?

Thanks

EDIT


I've also tried:

paragraphFromDocument.Range.CopyAsPicture
currentSlide.Shapes.PasteSpecial(ppPasteMetafilePicture)

and get this error message:

Shapes.PasteSpecial : Invalid Request. Clipboard is empty or contains data which may not be posted here.

But, when I use that CopyAsPicture command, I am able to open up PowerPoint (with the picture still on the clipboard from the macro) and use the Paste Special command to paste the picture to the slide.

Upvotes: 1

Views: 6508

Answers (1)

Stephen Watkins
Stephen Watkins

Reputation: 25775

paragraphFromDocument.Range.Copy
currentSlide.Shapes.Paste

actually did end up working, but I had to remove all special characters from the range first. That is why it was giving me the error message.

Upvotes: 1

Related Questions