主要参考这里的讨论.
我们直接采用如下VBS即可实现效果:
Sub AutoPlayMP3()
'一些申明,使得在PPT宏编辑中可以自动补全
Dim ppt As PowerPoint.Presentation
Dim sls As Slides
Dim sl As Slide
Dim sound As Shape
Set ppt = ActivePresentation
Set sls = ppt.Slides
'sl 表示所有slides中的一个slide,所有slides可以用sls.Range得到
For Each sl In sls.Range
'sound 表示本张幻灯片中所有形状
For Each sound In sl.Shapes
'判断形状是不是多媒体类型的
If sound.Type = msoMedia Then
'判断形状是不是声音类型的
If sound.MediaType = ppMediaTypeSound Then
'设置声音的位置
sound.Left = 0
sound.Top = 0
'设置自动播放该声音,通过在时间线中添加主序列的效果,并将其移到第一个动画
sl.TimeLine.MainSequence.AddEffect(sound, msoAnimEffectMediaPlay, , msoAnimTriggerWithPrevious).MoveTo 1
With sound.AnimationSettings
'设置后台播放声音
.AnimateBackground = msoTrue
'设置不播放时隐藏动画
.PlaySettings.HideWhileNotPlaying = True
'.PlaySettings.PlayOnEntry = True
'.PlaySettings.PauseAnimation = False
'.PlaySettings.StopAfterSlides = 0
End With
End If
End If
Next
Next
End Sub
网友评论