简体   繁体   English

如何以编程方式将图片从Word复制到Powerpoint?

[英]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. 我正在创建将Word 2007文档转换为结构化PowerPoint 2007演示文稿的宏。 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). 但是我还需要能够将Word文档中的图片复制并粘贴到PowerPoint中(以及段落之间的正确位置)。

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". 到目前为止,我可以通过查看段落的style属性来检测该段落是否为图片-它会显示“ 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? 如何将图片从Word复制到PowerPoint?

Thanks 谢谢

EDIT 编辑


I've also tried: 我也尝试过:

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

and get this error message: 并得到以下错误信息:

Shapes.PasteSpecial : Invalid Request. Shapes.PasteSpecial:无效的请求。 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. 但是,当我使用那个CopyAsPicture命令时,我能够打开PowerPoint(图片仍在宏的剪贴板上),并使用“选择性粘贴”命令将图片粘贴到幻灯片上。

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. 这就是为什么它给我错误信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM