如何选择幻灯片

时间:2015-04-15 17:44:27

标签: vsto powerpoint

我在WindowSelectionChange事件中,我想进入选择所在的幻灯片。有人能帮我一下吗。我尝试从选择的父级进行强制转换并抛出异常。

1 个答案:

答案 0 :(得分:0)

您的偶数处理程序将作为参数传递当前选择,例如

WindowSelectionChange(ByVal Sel As Selection)

所以你可以这样做:

With Sel

    Select Case .Type

        Case ppSelectionNone
            MsgBox "Nothing selected. Why did you wake me up?"

        Case ppSelectionShapes
            ' The Selection is a ShapeRange of one or more shapes
            ' The parent of the shaperange gives you a reference
            ' to the slide or slide master
            MsgBox "The current selection is on: " _
                    & .ShapeRange.Parent.Name

        Case ppSelectionSlides
            ' The selection is one or more slides
            ' Use something like this?
            If .SlideRange.Count > 1 Then
                MsgBox "One slide at at time. Please!"
            Else
                MsgBox "You've selected " & .SlideRange(1).Name
            End If

        Case ppSelectionText
            ' Generally:
            MsgBox "You've selected text on " & .TextRange.Parent.Parent.Parent.Name
            ' .Parent is the textrange
            ' .Parent.Parent is the shape
            ' .Parent.Parent.Parent is the slide holding the shape
            ' This will not work for text in table cells in some PPT versions

        Case Else
            MsgBox "ALIENS!  RUN!!!"

    End Select

 End With

注意:在事件处理程序中执行类似的操作是个好主意:

关闭事件处理 调用SomeOtherRoutine(Sel)'来完成实际工作

打开事件处理

这样你就不必担心你的其他例程会无意中触发事件或处理其他例程正在运行时发生的其他事件。