简体   繁体   English

在Powerpoint VBA中前进两张幻灯片

[英]Advancing two slides in powerpoint VBA

I am trying to advance slides based on a response. 我正在尝试根据响应推进幻灯片。 I want to go forward 2 slides if the user selects easy and one if they select hard. 如果用户选择“简单”,我想前进2张幻灯片,如果选择“困难”,我想前进1张幻灯片。 This is my current code. 这是我当前的代码。 The Nextpage script isn't working AND I would prefer for it to be usable for multiple questions--I can't seem to get it to work with something like slide +1 or slide +2 (or ++). Nextpage脚本无法正常工作,我希望它可用于多个问题-我似乎无法使其与幻灯片+1或幻灯片+2(或++)类似。

Sub Start()
    ActivePresentation.Slides(2).Shapes("selection_hard").Visible = False
    ActivePresentation.Slides(2).Shapes("selection_easy").Visible = False

    ActivePresentation.SlideShowWindow.View.Next
End Sub


Sub Shoe_Easy()
    ShoeAnswer = "Easy"

    ActivePresentation.Slides(2).Shapes("selection_hard").Visible = False
    ActivePresentation.Slides(2).Shapes("selection_easy").Visible = True

    'ActivePresentation.SlideShowWindow.View.GotoSlide (11)
End Sub



Sub Shoe_Hard()
    ShoeAnswer = "Hard"

    ActivePresentation.Slides(2).Shapes("selection_hard").Visible = True
    ActivePresentation.Slides(2).Shapes("selection_easy").Visible = False

    'ActivePresentation.SlideShowWindow.View.GotoSlide (12)
End Sub


Sub Nextpage()
    If ActivePresentation.Slides(2).Shapes("selection_hard").Visisble = True Then
        ActivePresentation.SlideShowWindow.View.GotoSlide (3)

    ElseIf ActivePresenation.Slides(2).Shapes("selection_easy").Visible = True Then
        ActivePresenation.SlideShowWindow.View.GotoSlide (4)
    End If
End Sub

Assuming that "response" means clicking on one of two shapes (Easy or Hard), this will do it. 假设“响应”是指单击两个形状(“容易”或“困难”)之一,则可以做到这一点。 You just need to make sure that the text in the shape and the code below match up and that you assign the HandleClick macro as a RunMacro action setting to each of the shapes (assign them to two of them then copy/paste the shapes elsewhere as needed). 您只需要确保形状中的文本和下面的代码匹配,并且将HandleClick宏作为RunMacro操作设置分配给每个形状(将它们分配给其中两个,然后将形状复制/粘贴到其他位置即可)需要)。

There are a few extra hoops to jump through to get this working on a Mac; 要在Mac上运行该功能,还需要进行一些调整。 shout if you need it to work there too. 如果您也需要在这里工作,请大声喊叫。

Sub HandleClick(oSh As Shape)

    ' Did they click the Easy or Hard button?
    ' oSh contains a reference to the shape they clicked
    ' Look a the text in oSh to decide where to go next:

    Select Case UCase(oSh.TextFrame.TextRange.Text)
        Case Is = "EASY"
            SlideShowWindows(1).View.GotoSlide (oSh.Parent.SlideIndex + 2)
        Case Is = "HARD"
            SlideShowWindows(1).View.GotoSlide (oSh.Parent.SlideIndex + 1)
        Case Else
            ' Do nothing
    End Select

End Sub

This immediately advances the slide as soon as it's clicked. 单击幻灯片后,幻灯片立即前进。 If you want the user to be able to choose an answer and then advance, you'd need a different approach. 如果您希望用户能够选择答案然后继续前进,则需要使用其他方法。

Instead of advancing immediately as above, you'd set the value of a global variable to, say, "EASY" or "HARD", depending on the user's selection. 您可以根据用户的选择将全局变量的值设置为“ EASY”或“ HARD”,而不是像上面那样立即前进。

Then in a separate macro assigned to your forward button, you'd advance one or two slides depending on the value of the global variable. 然后,在分配给前进按钮的单独宏中,根据全局变量的值前进一两张幻灯片。

I think something like this might help: 我认为这样可能会有所帮助:

Nextpage()
Dim currentSlide as Slide
Set currentSlide = ActivePresentation.SlideshowWindow.View.Slide

    If ActivePresentation.Slides(2).Shapes("selection_hard").Visisble = True Then
        ActivePresentation.SlideShowWindow.View.GotoSlide currentSlide.SlideIndex + 1

    ElseIf ActivePresenation.Slides(2).Shapes("selection_easy").Visible = True Then
        ActivePresenation.SlideShowWindow.View.GotoSlide currentSlide.SlideIndex + 2
    End If
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM