VBA Excel to Powerpoint,向前移动1张幻灯片

时间:2018-04-30 12:56:29

标签: excel-vba powerpoint-vba vba excel

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

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。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

你几乎就在那里 - 使用你的代码,只需添加PPT.ActivePresentation.Slides(2).Select

Private Sub OpenPowerpoint()

    Dim PPT As PowerPoint.Application
    Set PPT = New PowerPoint.Application

    PPT.Visible = True
    PPT.Presentations.Open Filename:="C:\Users\Person\Desktop\Test\Template.pptx"        
    PPT.ActivePresentation.Slides(2).Select

End Sub