首页 > 解决方案 > VBA Excel 到 Powerpoint,向前移动 1 张幻灯片

问题描述

我正在尝试创建一个打开应用程序的宏,然后向前移动一张幻灯片并使其成为我的活动幻灯片。我觉得有一个简单的解决方案,但我似乎无法找到一个代码来让我前进一张幻灯片。到目前为止我有

Private Sub OpenPowerpoint()
' Opens Presentation.pptx

Dim PPT As PowerPoint.Application
Set PPT = New PowerPoint.Application
PPT.Visible = True
PPT.Presentations.Open Filename:="C:\Users\Person\Desktop\Test\Template.pptx"

End Sub

在第一张幻灯片上打开我的 pp。

标签: excelpowerpointvba

解决方案


Window.View.GoToSlide将让您转到特定的幻灯片编号。
 
Window.View.Slide.SlideIndex会告诉您当前所在的幻灯片编号。
 
Presentation.Slides.Count将告诉您演示文稿中有多少张幻灯片,这样您就不会试图移动到最后。
 
把它放在一起:

Private Sub OpenPowerpoint()
    ' Opens Presentation.pptx

    Dim PPT As PowerPoint.Application, PPP As PowerPoint.Presentation, PPW As Object
    Set PPT = New PowerPoint.Application
    PPT.Visible = True
    Set PPP = PPT.Presentations.Open(FileName:="C:\Users\Person\Desktop\Test\Template.pptx")
    Set PPW = PPP.Windows(PPP.Windows.Count)
    'If there are more slides, go to the next one
    If PPW.View.Slide.SlideIndex < PPP.Slides.Count Then PPW.View.GotoSlide PPW.View.SlideIndex + 1
End Sub

推荐阅读