Powerpoint 2011 VBA 图像替换
所以我有一个 Powerpoint 演示文稿。它包含许多图像,由图像 X 引用。(因此它是相同的图像,但位于多个页面上)不同页面/幻灯片上的这些相同图像具有与其关联的不同宽度/高度属性。因此,即使它们是相同的图像,它们的大小也可能不同。
因此存在一种情况,图像存在于很多幻灯片上。我希望能够同时(快速)替换所有它们,而不必浏览每张幻灯片并单独替换 X,一次替换一个新图像。
- 这可能吗? (是/否)
- 这将如何实现? (摘要 - 只需要高级解释)
So I have a Powerpoint presentation. It contains numerous images on it, referred to by image X. (So it's the same image but on multiple pages) These same images on different pages/slides have different width/height attributes associated to them. So even though they're the same image, they may not be the same size.
So there exists a scenario where an image exists on a lot of the slides. I want the ability to replace all of them at the same time (quickly) without having to go through each slide and separately replacing X, one at a time with the new image.
- Is this possible? (yes/no)
- How would this be accomplished? (abstract - high level explanation is only required)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许是可能的。当您在单个演示文稿中插入图像,然后将其从一张幻灯片复制到另一张幻灯片时,PPT 仅保留一张原始图像。其他实例是指向第一张图像的内部指针。在某些情况下,它还会检测到用户多次插入同一张图片,在这种情况下它会执行相同的操作;创建指向原始图像的指针,而不是插入图像的新实例。
我已经有一段时间没有使用这个了,但有一次,我能够在 XML 中跟踪它从一张幻灯片到另一张幻灯片跟踪复制图像的方式,再回到原始图像。
因此,如果图像正常插入(而不是复制/粘贴或作为对象插入),然后从原始插入的图像复制粘贴到其他幻灯片,您可以通过替换 XML 中的原始图像来执行您想要的操作。
创建文件后,我想不出任何其他方式可以发生这种情况。
如果您可以控制如何在将来的演示文稿中插入图像,则可以进行一些设置,以便可以相当简单地完成此操作。
It might be possible. When you insert an image and then copy it from one slide to another within a single presentation, PPT maintains just the one original image. The other instances are internally pointers to the first image. And in some cases, it will also detect that a user has inserted the same picture multiple times, in which case it'll do the same thing; create a pointer to the original rather than inserting a new instance of the image.
It's been some time since I played with this, but at one point, I was able to trace the way it tracked a copied image from slide to slide, back to the original, in the XML.
So IF the images were inserted normally (rather than copy/pasted in or inserted as objects) and then copy pasted from the original inserted image to other slides, you may be able to do what you want by replacing the original image in the XML.
I can't think of any other way this can happen once the file's been created.
If you have control over how images get inserted in future presentations, you could set things up so that you can do this rather simply, though.
在 Open XML 中这是可能的 - 只要您知道您在寻找什么。每张幻灯片(以及每个幻灯片布局)都是一个 XML 文件。这些 XML 文件采用开放打包约定格式,维护带有 .rels 扩展名的关系文件。因此,如果您的第一张幻灯片是 slide1.xml,那么它的关系文件是 slide1.xml.rels。这是为每张幻灯片保存图像参考的位置。
.rels 文件如下所示:
您会注意到第 2 项和第 3 项通过其
类型
引用图像。当您在 PowerPoint 中插入图像时,原始名称是什么不再重要,PowerPoint 会对其进行重命名。因此,如果它是 My_Climb_Up_Denali.jpg,它将被重命名为类似 image1.jpg 的名称。
所以这里的问题是知道您正在寻找哪个图像。在
元素中,有一个属性 ...@name 通常保留它感兴趣的文件路径(但有时会有所不同,例如当您插入来自剪贴画)。无论如何,这只是记住您要查找的内容的一种半可靠的方式。所以你可能需要查看包的内部内容才能找到图片的重命名名称。
Office 中有关于此主题的操作方法Open XML 格式:替换 PowerPoint 2007 幻灯片图像 这可能会有所帮助。
It is possible in Open XML - provided you know what you're looking for. Every slide (and every slide layout) is an XML file. These XML files, in the Open Packaging Convention format, maintain a relationship file with a .rels extention. So if your first slide is slide1.xml, then it's relationship file is slide1.xml.rels. That is the location where an image's reference is kept for each slide.
The .rels file looks like this:
You'll notice that items 2 and 3 reference images by their
Type
.When you insert an image in PowerPoint, it no longer matters what the original name was, PowerPoint renames it. So if it was My_Climb_Up_Denali.jpg, it will be renamed to something like image1.jpg.
So the issue here is knowing which image you are looking for. In the
<p:pic>
element, there is an attribute ...@name which usually retains the file path it was interested from (but it will be different sometimes, like when you've inserted from clip art). Regardless, that is only a semi-reliable way of remembering what you are looking for.So you may need to view the internal contents of the package to find the renamed name of the pic.
There is a How-To on this subject at Office Open XML Formats: Replacing PowerPoint 2007 Slide Images which may be helpful.