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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4926828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 12:37:50  来源:igfitidea点击:

How to copy picture from Word to Powerpoint programmatically?

vbams-wordpowerpointpowerpoint-vba

提问by Stephen Watkins

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.

我正在创建一个将 Word 2007 文档转换为结构化 PowerPoint 2007 演示文稿的宏。我正在遍历文档的所有段落并将它们复制到新的演示文稿中。

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". 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. Clipboard is empty or contains data which may not be posted here.

Shapes.PasteSpecial:无效请求。剪贴板为空或包含可能不会在此处发布的数据。

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(图片仍在剪贴板上来自宏)并使用选择性粘贴命令将图片粘贴到幻灯片上。

采纳答案by Stephen Watkins

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.

实际上最终确实有效,但我必须首先从范围中删除所有特殊字符。这就是为什么它给我错误信息。