【问题标题】:VBA PowerPoint - Go back to the slide I came fromVBA PowerPoint - 回到我来自的幻灯片
【发布时间】:2012-09-02 21:51:03
【问题描述】:

我将如何做到这一点?因为我不断地添加和删除幻灯片,所以我需要代码来了解我来自哪张幻灯片,而不仅仅是转到一组幻灯片。

【问题讨论】:

  • Go back to the slide I came from 是什么意思。您是通过代码移动,还是您的意思是每次手动删除或插入要返回到先前选择的幻灯片的幻灯片?如果在多幻灯片删除中删除上一张幻灯片怎么办?
  • 我想通了,但我感觉到该代码有限制。

标签: vba button controls slide powerpoint


【解决方案1】:
 SlideShowWindows(1).View.GotoSlide(SlideShowWindows(1).View.LastSlideViewed.SlideIndex)

【讨论】:

  • 这比我用的简单多了,哈哈!
【解决方案2】:

我想通了。在浏览网页的帮助和一些思考下,我想出了这个:

为了存储当前幻灯片编号,除了需要您返回另一张幻灯片的幻灯片,我制作了一个模块:

Public CurrentSlide As Long, PreviousSlide As Long

Public Sub GoToPreviousSlide()
SlideShowWindows(1).View.GoToSlide (PreviousSlide)
End Sub

Public Sub StoreCurrentSlide()
CurrentSlide = ActivePresentation.SlideShowWindow.View.Slide.SlideIndex
If CurrentSlide <> 14 Then
'Execute only if the current slide is not a slide that uses this function (because if you store the current slide while in a slide that requires you to go back to another slide, it will overwrite the PurrentSlide value and render this useless). Add more slide numbers to the If statement as you need them.
PreviousSlide = CurrentSlide
Call GoToPreviousSlide
End If
End Sub

当然,我必须确保每次幻灯片更改时都调用 StoreCurrentSlide,我创建了另一个模块来自动执行此操作:

Public Sub OnSlideShowPageChange()
StoreCurrentSlide
End Sub

现在我可以在任何地方使用按钮并使用以下方法返回上一张幻灯片:

Private Sub OK_Click()
GoToPreviousSlide
End Sub

【讨论】:

    【解决方案3】:

    如果你使用的是按钮,为什么不使用 PPT 的动作设置;分配先前查看的幻灯片的操作设置。单击该按钮将使查看者返回到当前幻灯片之前他们正在查看的任何幻灯片。

    不需要 VBA。

    【讨论】:

    • 我对操作设置的体验很糟糕,但那是在 Office 2003 中。它会先于幻灯片,而不是我来自的幻灯片。比如说如果我从幻灯片 2 跳到 5 并想返回,动作设置会将我带到 4。
    • 迟到总比没有好,我想:您描述的是上一张幻灯片操作发生的情况,而不是之前查看的幻灯片。但你解决的方法不同,所以没关系。
    【解决方案4】:

    [Microsoft 365] 在演示文稿(幻灯片放映)中,键入数字并按 Enter。编辑幻灯片时,我使用保存在文件“Macros.pptm”中的这个 VBA 宏:

    Sub GoToSlide()
    Dim currNum As Integer, newNum As Integer, a As String
    currNum = _ 
    CInt(Application.ActiveWindow.View.Slide.SlideIndex)
    a = InputBox("Current slide [" & currNum & "]:" & _ 
    vbCrLf & _"Go to slide number:", _
    "GoToSlide", currNum)
    If (a <> "") Then
    newNum = CInt(a)
    Application.ActiveWindow.View.GoToSlide (newNum)
    End If
    End Sub
    

    我已将此宏作为新命令分配给快速访问功能区。当我编辑一个牌组时,我也必须打开文件“Macro.pptm”才能找到宏。 宏显示当前幻灯片编号并提示输入所需的幻灯片编号,然后转到那里(除非用户按 ESC)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-07
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多