Powerpoint 2011 VBA Image Replacement
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.
S开发者_JAVA百科o 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)
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:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship
Id="rId3"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout"
Target="../slideLayouts/slideLayout3.xml"/>
<Relationship
Id="rId7"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
Target="../media/image3.png"/>
<Relationship
Id="rId6"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
Target="../media/image2.wmf"/>
<Relationship
Id="rId4" T
ype="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide"
Target="../notesSlides/notesSlide1.xml"/>
</Relationships>
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.
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.
精彩评论