vba - 使用 VBA 在 PowerPoint 中的特定幻灯片上淡出背景媒体的音量
问题描述
我有一个以自动播放媒体文件开头的 PowerPoint。第一张幻灯片被编程为在 20 秒后转换,同时音乐一直在播放。我希望它在幻灯片放映期间继续播放,但在第二张幻灯片出现后淡出到较低的音量,并在演示的其余部分保持这种状态。我已经在宏中查看了这个 Powerpoint 更改音效音量,但它似乎不能满足我的需求。
我试过这个:
Sub fadeVolSlideChange(ByVal ShowPos As SlideShowWindow)
Dim ShowPos As Integer
Dim bkgMusic As Shape
Dim Step As Long
ShowPos = ShowPos.View.CurrentShowPosition
Set bkgMusic = ActiveWindow.Selection.ShapeRange(1)
If ShowPos = 2 Then
Set Step = 0.05
For i = 1 To 0.5
With bkgMusic.MediaFormat
.Volume = i
.Muted = False
End With
i = i - Step
Application.Wait (Now + 0.0000025)
Next i
End If
End Sub
没有运气。想法?
这是最新的编辑(仍然没有运气让它工作):
Sub OnSlideShowPageChange()
Dim i As Integer
Dim bkgMusic As Shape
Dim bkgVol As Long
Dim inc As Long
i = ActivePresentation.SlideShowWindow.View.CurrentShowPosition
Set bkgMusic = ActivePresentation.Slides(1).Shapes("Opening Theme")
If i = 1 Then
'Do nothing
ElseIf i <> 1 Then
inc = 0.05
For bkgVol = 1 To 0.1
With bkgMusic.MediaFormat
.Volume = bkgVol
.Muted = False
End With
bkgVol = bkgVol - inc
Application.Wait (Now + TimeValue("0:00:01"))
Next bkgVol
End If
End Sub
解决方案
这几乎行得通,但 PPT 最终让我们失望了。运行后,声音文件的音量降低了,但在幻灯片播放过程中并没有改变。
Sub OnSlideShowPageChange()
Dim i As Integer
Dim bkgMusic As Shape
' This needs to be single, not Long
Dim bkgVol As Single
Dim inc As Long
Dim lCounter As Long
i = ActivePresentation.SlideShowWindow.View.CurrentShowPosition
Set bkgMusic = ActivePresentation.Slides(1).Shapes("Opening Theme")
If i = 2 Then
inc = 0.05
' Changing the value by fractions so must be a single, not a long, and
' decreasing the value requires Step and a negative number:
For bkgVol = 1 To 0.1 Step -0.1
With bkgMusic.MediaFormat
.Volume = bkgVol
.Muted = False
End With
'bkgVol = bkgVol - inc
' Application.Wait is not supported in PPT
'Application.Wait (Now + TimeValue("0:00:01"))
WaitForIt
SlideShowWindows(1).View.GotoSlide (2)
Next bkgVol
End If
End Sub
Sub WaitForIt()
Dim x As Long
For x = 1 To 1000000
DoEvents
Next
'MsgBox "Done waiting"
End Sub
推荐阅读
- c++ - GCC/Clang 分歧:是否
匹配 在 C++17 模板模板替换中? - javascript - Vue.js:如何通过 SourceMap 或捆绑文件打开/处理现有项目
- python - raspberrypi 到 raspberrypi /bluetooth/errorcode 111,连接被拒绝
- c++ - 如果编译后的源代码特定于编译它的硬件,我们如何分发它?
- html - ng-persian-datepicker 在打开时将其他元素向下推
- python-3.x - 无法通过 googlecolab 中的 PIL 打开图像
- jquery - 我的选择自动填充 onchange 非常慢
- python - 如何修复 python pyglet 错误以进行播放和暂停?
- javascript - 为什么返回 arr.includes() 与在验证同一数组的条件语句中返回 true 不同?
- python - ValueError:形状 (None, 2) 和 (None, 1) 不兼容