简体   繁体   English

使用 VBA 在 Powerpoint 中的一张幻灯片上静音和取消静音多个音频媒体

[英]Muting and Unmuting multiple audio media on one slide in Powerpoint using VBA

I use PowerPoint 2016 on Windows 10. Slide A has a text box and a command button.我在 Windows 10 上使用 PowerPoint 2016。幻灯片 A 有一个文本框和一个命令按钮。 When the command button is selected, a boolean gbool is set and the presentation advances to Slide B.当命令按钮被选中时,一个布尔gbool被设置并且演示文稿前进到幻灯片 B。

ActivePresentation.SlideShowWindow.View.GotoSlide <slideB slideindex> 

On Slide B, there are two audio media objects, AM1 and AM2.在幻灯片 B 上,有两个音频媒体对象,AM1 和 AM2。 What I want to happen is if gbool is True then AM1 should play else AM2 should play.我想要发生的是,如果gbool为 True,那么 AM1 应该播放,否则 AM2 应该播放。 I have used the muted flag to attempt this:我已经使用静音标志来尝试这个:

Shape.MediaFormat.Muted = False

The problem I have is that, this sometimes works, other times both audio medias will play.我的问题是,这有时有效,有时两个音频媒体都会播放。 The code looks like this:代码如下所示:

Private Sub CommandButton1_Click()
    Dim osl As Slide, oSh As Shape, gbool As Boolean
    gbool = function()

    Set osl = ActivePresentation.Slides(<slideB slideindex>)
    Set oSh = osl.Shapes("AM1")
    oSh.MediaFormat.Muted = gbool
    Set oSh = osl.Shapes("AM2")
    oSh.MediaFormat.Muted = Not gbool

   ActivePresentation.SlideShowWindow.View.GotoSlide <slideB slideindex>
End Sub

Any ideas for the random behaviour and is there a better way to do this?关于随机行为的任何想法,有没有更好的方法来做到这一点?

I think I have an answer - at least this method works all the time.我想我有一个答案——至少这种方法一直有效。 Instead of using the muted property of the MediaFormat object, I now use the PlayOnEntry property of the Play Settings object.我现在不使用 MediaFormat 对象的静音属性,而是使用播放设置对象的 PlayOnEntry 属性。 So the change looks like this:所以变化看起来像这样:

Set osl = ActivePresentation.Slides(<slideB slideindex>)
Set oSh = osl.Shapes("AM1")
oSh.AnimationSettings.PlaySettings.PlayOnEntry = gbool
Set oSh = osl.Shapes("AM2")
oSh.AnimationSettings.PlaySettings.PlayOnEntry = Not gbool

If there is a better way, I would appreciate to know it.如果有更好的方法,我将不胜感激。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM