我想使用PowerPoint VBA(Microsoft 365 MSO)向PowerPoint幻灯片中添加两个声音形状,都在单击时触发。
幻灯片时间轴将是:
我能够放置声音形状并添加动画对象以触发声音。
代码将添加一个新的幻灯片,创建两个声音形状,并在单击时触发它们,但是声音1不会停止播放。
Sub TestSoundTrigger()
Dim slTestSoundSlide As Slide
Dim shSoundShape1 As Shape
Dim shSoundShape2 As Shape
Dim efSoundShape1 As Effect
Dim efSoundShape2 As Effect
' Create the slide
Set slTestSoundSlide = ActivePresentation.Slides.AddSlide(ActivePresentation.Slides.Count + 1, ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1))
' Add 2 sound shapes
Set shSoundShape1 = slTestSoundSlide.Shapes.AddMediaObject2(ActivePresentation.Path & "\testsound1.mp3", True, False, 10, 10)
Set shSoundShape2 = slTestSoundSlide.Shapes.AddMediaObject2(ActivePresentation.Path & "\testsound2.mp3", True, False, 10, 10)
' Add the 2 triggers to play the sounds on click in turn
Set efSoundShape1 = slTestSoundSlide.TimeLine.MainSequence.AddEffect(shSoundShape1, effectId:=msoAnimEffectMediaPlay)
Set efSoundShape2 = slTestSoundSlide.TimeLine.MainSequence.AddEffect(shSoundShape2, effectId:=msoAnimEffectMediaPlay)
End Sub
我已经检查了“效果”和“时间轴”对象的属性,但是找不到该属性。
答案 0 :(得分:1)
我找到了此属性:ppSoundStopPrevious ppSoundEffectType
或者 您可以设置另一个msoAnimEffectMediaStop-但这将创建另一个动画步骤
Sub TestSoundTrigger()
Dim slTestSoundSlide As Slide
Dim shSoundShape1 As Shape
Dim shSoundShape2 As Shape
Dim efSoundShape1 As Effect
Dim efSoundShape2 As Effect
' Create the slide
Set slTestSoundSlide = ActivePresentation.Slides.AddSlide(ActivePresentation.Slides.Count + 1, ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1))
' Add 2 sound shapes
Set shSoundShape1 = slTestSoundSlide.Shapes.AddMediaObject2(ActivePresentation.Path & "\testsound1.mp3", True, False, 10, 10)
Set shSoundShape2 = slTestSoundSlide.Shapes.AddMediaObject2(ActivePresentation.Path & "\testsound2.mp3", True, False, 10, 10)
' Add the 2 triggers to play the sounds on click in turn
Set efSoundShape1 = slTestSoundSlide.TimeLine.MainSequence.AddEffect(shSoundShape1, effectId:=msoAnimEffectMediaPlay)
Set efSoundShape1 = slTestSoundSlide.TimeLine.MainSequence.AddEffect(shSoundShape1, effectId:=msoAnimEffectMediaStop)
Set efSoundShape2 = slTestSoundSlide.TimeLine.MainSequence.AddEffect(shSoundShape2, effectId:=msoAnimEffectMediaPlay)
End Sub