如何在PowerPoint VBA中以给定的时间/时间间隔关闭幻灯片视图



我最近启动了VBA,并正在尝试制作一个可以打开PowerPoint文件(Compute_dashboard.pptx(并将其放在幻灯片视图中的项目。它将穿过幻灯片和循环,直到达到特定的时间范围。在下面的此代码中,它应在上午10:10:00 -10:10:10 AM退出,并退出PowerPoint。我有两个不同的实现,每个实现都有自己的问题,如果您能找到一种纠正其中的方法,那将是很棒的。

通过我的第一个实现,它将打开文件,然后在时钟达到该时间范围之前,PowerPoint才能响应,然后将其删除。因此,主要的问题是我完全看不到幻灯片运行。

    Sub OpenFile()
    Set pptApp = CreateObject("PowerPoint.Application")
    pptApp.Visible = True
    Set pptPres = pptApp.Presentations.Open("Compute_Dashboard.pptx")
    ActivePresentation.SlideShowSettings.Run
    Dim b As Boolean
    b = True
        While b = True
        If Time() > TimeValue("10:10:00") And Time() < TimeValue("10:10:10") Then
                b = False
                ActivePresentation.SlideShowWindow.view.Exit
                Application.Quit
        End If
            With ActivePresentation.Slides(1).SlideShowTransition
                    .AdvanceOnTime = msoTrue
                     .AdvanceTime = 3         
            End With 
        Wend

使用第二个实现,它可以正确打开文件和幻灯片循环,但是我无法在我的时间范围内删除幻灯片和PowerPoint。


     Sub OpenFile()
     Set pptApp = CreateObject("PowerPoint.Application")
     pptApp.Visible = True
     Set pptPres = pptApp.Presentations.Open("Compute_Dashboard.pptx")
     ActivePresentation.SlideShowSettings.Run
     For Each s In ActivePresentation.Slides
         With s.SlideShowTransition
              .AdvanceOnTime = msoTrue
              .AdvanceTime = 3
      If Time() > TimeValue("10:10:00") And Time() < TimeValue("10:10:10") Then
                ActivePresentation.SlideShowWindow.view.Exit
                Application.Quit
      End If
      End With
     Next

尝试此

Sub OpenFile()
Set pptApp = CreateObject("PowerPoint.Application")
pptApp.Visible = True
Set pptPres = pptApp.Presentations.Open("Compute_Dashboard.pptx")
ActivePresentation.SlideShowSettings.Run
For Each s In ActivePresentation.Slides
     With s.SlideShowTransition
          .AdvanceOnTime = msoTrue
          .AdvanceTime = 3
     End With
Next s
Dim b As Boolean
b = True
    While b = True
    If Time() > TimeValue("10:10:00") And Time() < TimeValue("10:10:10") Then
            b = False
            ActivePresentation.SlideShowWindow.view.Exit
            Application.Quit
    End If
    Wend

我不确定您在这里的意图100% - 猜想您只想将幻灯片的进步时间设置为每张幻灯片的3秒钟,然后在一定时间退出。

设置幻灯片进步时间不是触发幻灯片以进步。它只是为该幻灯片设置该属性 - 3秒后提前。

由于它在程序运行时会在眼睛的眨眼中为所有幻灯片设置这些属性,因此它在程序运行时有效地检查了退出要求,因此永远不会退出。

最新更新