Playing Sound Clips Without Seeing the Icon

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.

Sub AddAudioOffSlide()

Dim shpSound As Shape

With ActivePresentation.Slides(2).Shapes

Set shpSound = .AddMediaObject _


With shpSound

.Left = 0 - .Width

.Top = 0 - .Height

With .AnimationSettings

.Animate = msoTrue

.AnimationOrder = 1

.EntryEffect = ppEffectNone

.PlaySettings.PlayOnEntry = msoTrue

.AdvanceMode = ppAdvanceOnTime

.AdvanceTime = 0

End With

End With

End With

End Sub

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.