我正在尝试创建一个宏,它将在powerpoint演示文稿中运行幻灯片。我有它工作,但现在它已停止工作,我不知道为什么。
运行幻灯片和动画的vbscript是
Private Sub PPTEvent_SlideShowNextBuild(ByVal Wn As SlideShowWindow)
Sleep 1000
SendKeys "{RIGHT}"
End Sub
Private Sub PPTEvent_SlideShowNextSlide(ByVal Wn As SlideShowWindow)
Sleep 1000
SendKeys "{RIGHT}"
End Sub
有没有更好的方法来实现这一目标?我看不出问题出在哪里,我也试过去掉Sleep 1000,但没有骰子。
奇怪的是,如果我同时使用
SendKeys "{ENTER}"
SendKeys "{RIGHT}"
一起,它按照我的希望贯穿整个幻灯片。
答案 0 :(得分:2)
以下是基于SlideShowSettings
帮助的另一种方法MSDN页面中有一个错误,我在下面已经更正了(对于LoopUntilStopped,需要使用msoTrue / False而不是True / False)。
当您进入幻灯片模式并且动画运行正常时,它会自动启动。
在标准模块中......
Public showRunning As Boolean
Sub runSlides()
showRunning = True
For Each s In ActivePresentation.Slides
With s.SlideShowTransition
.AdvanceOnTime = msoTrue
.AdvanceTime = 1
End With
Next
With ActivePresentation.SlideShowSettings
.RangeType = ppShowAll
.AdvanceMode = ppSlideShowUseSlideTimings
.LoopUntilStopped = msoFalse
.ShowWithAnimation = msoTrue
.Run
End With
End Sub
Public Sub OnSlideShowPageChange(ByVal Wn As SlideShowWindow)
If Not showRunning Then
runSlides
End If
End Sub
Public Sub OnSlideShowTerminate(ByVal Wn As SlideShowWindow)
showRunning = False
closeSlideShow
End Sub
Public Sub closeSlideShow()
Dim s As Slide
For Each s In ActivePresentation.Slides
With s.SlideShowTransition
.AdvanceOnTime = msoFalse
End With
Next
On Error Resume Next
ActivePresentation.SlideShowWindow.View.Exit
On Error GoTo 0
End Sub
编辑:
添加了closeSlideShow例程,以便每次都停止幻灯片显示。
注意:以编程方式或手动取消选中将.AdvanceOnTime设置为msoFalse在“幻灯片显示”功能区选项卡中使用“计时”将阻止幻灯片显示运行。似乎将此设置为msoTrue,已经输入设置为msoFalse,并尝试在同一例程中执行ActivePresentation.SlideShowSettings.Run将无法正常工作!
答案 1 :(得分:1)
一般来说,应避免使用SendKeys。你为什么不尝试像
这样的东西Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub GoThroughSlides()
Dim sl As PowerPoint.Slide
ActivePresentation.SlideShowSettings.Run
For Each sl In ActivePresentation.Slides
Sleep 3000 '
ActivePresentation.SlideShowWindow.Activate
SlideShowWindows(1).View.GotoSlide sl.SlideNumber
Next sl
End Sub