SharePoint Development from a Documentation Perspective
So here it is, my first official blog entry dealing with programming PowerPoint presentations. It’s a modest tip, but then, I’m still learning my way around the PowerPoint object model.
When you insert a sound clip into a PowerPoint presentation, a small icon representing the sound file appears on the specified slide. Which is fine if you intend to start the sound file playing by user interaction, that is, by clicking on the icon or moving your mouse over top of it. But what if you just want the clip to play automatically when the slide loads? Then the icon is just visual clutter.
In the user interface, if you drag the icon off into the ‘work space’ area around the slide, then the icon won’t appear during the presentation. Just remember to set the sound clip to play automatically when the slide appears, however, because without the icon you don’t have any way to start the slide during the presentation itself.
The following code does the same thing programmatically. First, it inserts the sound file. Then it moves the sound file (now represented by a Shape object, the icon) over to above the upper left hand corner of the slide. Then it sets several properties of the AnimationSettings object, which controls the playback behavior of the sound file. Specifically, the sound file is set to be the first shape on the slide animated, but to have no entry effect (so it just appears—or rather, doesn’t, as it’s positioned off the slide), and to play as soon as it appears, which is when the slide appears.
Dim shpSound As Shape
Set shpSound = .AddMediaObject _
.Left = 0 - .Width
.Top = 0 - .Height
.Animate = msoTrue
.AnimationOrder = 1
.EntryEffect = ppEffectNone
.PlaySettings.PlayOnEntry = msoTrue
.AdvanceMode = ppAdvanceOnTime
.AdvanceTime = 0
I believe you could also set the sound file to play in conjunction with another shape’s animation by setting the AnimationSettings.AnimationOrder of both Shape objects to the same value, but I haven’t tested that. And anyway, if you just wanted to play the sound file once as part of another shape’s animation, you can just use the AnimationSettings.SoundEffect property to do that, without having to add the sound file to the slide at all.
Hey, remember that nifty tip in my last blog entry about how to set up a sound file so that’s it’s ‘invisible’ and plays automatically when the slide loads? Nice trick, huh? Turns out that entry, in addition to being my first official PowerPoint blog entry, afforded me the rare opportunity to be horribly wrong with my advice in two completely different ways. Not only should you not set up the file to play automatically using the code I wrote, but even if you wrote the correct code, it might well screw up other animation effects for your entire slide.
Here’s the deal:
Unbeknownst to me at the time, it turns out that in PowerPoint 2002 and above there are actually two separate, incompatible sections of the object model that enable you to set up animation effects for your slide. The new, expanded object model section, contained in the TimeLine object, provides more flexibility and options for richer interactive animations then ever before. This is the object model section you should use for animation whenever possible. The other section, contained in the AnimationSettings object, was retained strictly for backward compatibility reasons. Unless you’re programming for PowerPoint 2000 and below, never use the Animation Settings object. (This, of course, make me wonder why this section of the object model wasn’t hidden for PowerPoint 2002 and above, but that’s a minor digression.)
Still with me? Because of basic differences in the way they are organized, the two object models are not compatible. The AnimationSettings object model only supports entry effects for shapes (which is one reason the TimeLine object model was created, to offer users multiple effects for a single shape.) Here’s where the fun begins. If your code uses the AnimationSettings object to set any effect properties, PowerPoint assumes you are programming for PowerPoint 2000 or below, and therefore deletes any animation effects that are not entry effects, for the entire slide. This includes effects that were added using the user interface.
So naturally, the code I wrote for my tip inserted the sound file ‘offscreen’, and then used the AnimationSettings object to set the file to play when the slide loaded. Let me apologize right now if I blew up anyone’s slide and you’ve been trying to figure out why ever since.
Now, normally at this point, having finished my mea culpa, I would show you the proper way to set the file to play automatically, using the TimeLine object model.
Except it doesn’t work that way either.
Turns out there’s currently a bug in the PowerPoint object model. You set a file to play automatically by setting PlaySettings.PlayOnEntry to True. You can access the PlaySettings object through either object model. Unfortunately, because of the bug, when you access certain properties of the PlaySettings object, even if you do so through the TimeLine object model, PowerPoint assumes you are programming for PowerPoint 2000 or below, and—you guessed it—deletes any animation effects that are not entry effects, for the entire slide.
This is true for the following PlaySettings properties: ActionVerb, HideWhileNotPlaying, PauseAnimation, PlayOnEntry, and StopAfterSlides. It seems like you can access the following two properties and not suffer any ill effects, but no guarantees: LoopUntilStopped and RewindMovie.
Did I mention that I was still learning my way around the PowerPoint object model?
Actually, I’m in the process right now of writing several articles on how to create, customize and control animation effects in PowerPoint. And unlike these helpful blog entries, the articles will be tech reviewed by developers on the PowerPoint team. Stay tuned.