VBA PowerPoint - 回到我来自的幻灯片

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12344756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 17:39:48  来源:igfitidea点击:

VBA PowerPoint - Go back to the slide I came from

vbabuttoncontrolsslidepowerpoint-vba

提问by dennis96411

How would I accomplish this? Because I'm constantly adding and deleting the slides, I need the code to KNOW what slide I came from and not just go to a set slide.

我将如何做到这一点?因为我一直在添加和删除幻灯片,所以我需要代码来知道我来自哪个幻灯片,而不仅仅是转到一组幻灯片。

回答by pinkfloydx33

 SlideShowWindows(1).View.GotoSlide(SlideShowWindows(1).View.LastSlideViewed.SlideIndex)

回答by dennis96411

I figured it out. With some help from browsing the web and a bit of thinking, I came up with this:

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

For storing the current slide number except the slides that requires you to go back to another slide, I made a module with:

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

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

Of course I'd have to make sure that I call StoreCurrentSlide every time the slide changes, I made another module to automatically execute this:

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

Public Sub OnSlideShowPageChange()
StoreCurrentSlide
End Sub

Now I can use a button anywhere and go back to the previous slide by using:

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

Private Sub OK_Click()
GoToPreviousSlide
End Sub

回答by Steve Rindsberg

If you're using a button anyhow, why not use PPT's action settings; assign an action setting of Previously Viewed Slide. Clicking the button will take the viewer back to whatever slide they were viewing immediately prior to the current slide.

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

No VBA required.

不需要VBA。