问题描述
我的 Office 365 PowerPoint 演示文稿只有一张幻灯片。幻灯片包含一个嵌入(未链接,非 OLE)视频的形状,我最初从 .mp4 文件插入了该视频。当我点击它时视频开始播放,但我需要从 VBA 代码控制它。我试过的任何东西(见下文)都不起作用,当然我没有收到错误消息或任何类型的反馈。如何从代码开始(和停止)视频?
Sub PlayVideo(Name)
Set Shape = GetShape(Name)
' Shape.MediaType == ppMediaTypeMovie
With Shape.AnimationSettings
.Animate = msoTrue
.AdvanceMode = ppAdvanceOnTime
.AdvanceTime = 0
.TextLevelEffect = ppAnimateByAllLevels
With .PlaySettings
.PlayOnEntry = msoTrue
.PauseAnimation = msoFalse
.LoopUntilStopped = msoTrue
End With
End With
With Slide.TimeLine.MainSequence
Set AnimationEffect = .AddEffect(Shape:=Shape,effectid:=msoAnimEffectMediaPlay)
With AnimationEffect
Set BehavIoUr = .Behaviors.Add(msoAnimTypeCommand)
With BehavIoUr
.CommandEffect.Type = msoAnimCommandTypeVerb
.CommandEffect.Command = "play"
End With
End With
End With
End Sub
解决方法
开始使用视频
SlideShowWindows(1).View.Player("algorithm panel").Play
停止视频使用
SlideShowWindows(1).View.Player("algorithm panel").Stop
这是一个例子。将其粘贴到模块中。我的视频名称是 SAMPLE.mp4
Option Explicit
Sub StartVideo()
SlideShowWindows(1).View.Player("SAMPLE").Play
End Sub
Sub StopVideo()
SlideShowWindows(1).View.Player("SAMPLE").Stop
End Sub
接下来在幻灯片中插入 2 个动作按钮并分配宏
我们已经完成了。