6

我有一些代码需要我知道SlideIndex要操作什么(例如,在哪里插入新幻灯片,在哪里插入 ChartObject 等)。大约 99% 的时间,我可以通过以下方式成功获得SlideIndex

Dim w as Long 'slide index variable
w = ActivePresentation.Windows(1).Selection.SlideRange(1).SlideIndex

其他 0.1% 的时间,当 时ActivePresentation.Windows(1).SelectionType = ppSelectionNone,它会失败,因为(可以理解)它无法获得SlideIndex选择的 ,因为没有选择。如果用户无意中“选择”了大纲窗格中两张幻灯片之间的空间,则可能会发生这种情况。

理想情况下,我想做的是获取SlideIndex幻灯片窗格中可见的幻灯片属性:

在此处输入图像描述 我目前有一些代码可以测试是否SelectionTypeppSelectionNone,所以我可以捕获条件,我只是还没有找到一种方法来识别幻灯片窗格的 slideIndex。

Function GetMySlide()
Dim w as Long
    If Not ActivePresentation.Windows(1).Selection.Type = ppSelectionNone Then

        w = ActivePresentation.Windows(1).Selection.SlideRange(1).SlideIndex
        Set GetMySlide = ActivePresentation.Slides(w)

    Else:

        MsgBox "No slide is currently selected. Please select a slide in the Outline pane in order to proceed.", vbInformation
        Set GetMySlide = Nothing
        Exit Function
    End If
End Function

更新

我的临时解决方案是使用公共变量lastUsedSlide来尝试跟踪最近选择的幻灯片。我可以将它与WindowSelectionChange事件结合起来,但希望有一个更直接的解决方案。如果我认为这种方法总是有效,我会使用它,但是,它可能会引入不可预见的错误,因为lastUsedSlide它不是what_slide_i_am_currently_looking_at.

4

2 回答 2

3

潜在的解决方法,在这里:

http://eileenslounge.com/viewtopic.php?f=30&t=1667

If ActiveWindow.Selection.Type = ppSelectionNone Then
  Select Case ActiveWindow.ViewType
    Case ppViewNormal
      ActiveWindow.ViewType = ppViewSlide
      ActiveWindow.ViewType = ppViewNormal
    Case ppViewSlideSorter
      ActiveWindow.ViewType = ppViewSlide
      ActiveWindow.ViewType = ppViewSlideSorter
    Case Else
      ' ?
  End Select
End If
' A slide should be selected now

从美学上讲,我并不特别在意它,但它似乎有点用。唯一的事情是,如果选择在幻灯片之间,这会强制选择这两张幻灯片中的第一张,而我认为第二张会更直观。我可以修改我的代码来解决这个问题,但这仍然不理想。

于 2013-05-20T15:47:23.350 回答
2

大卫,也许你可以对这样Activate的对象使用额外的方法Window.Pane

'new code:
ActivePresentation.Windows(1).Panes(2).Activate
'your code
Dim w as Long 'slide index variable
w = ActivePresentation.Windows(1).Selection.SlideRange(1).SlideIndex

但是,请阅读更多关于Pane.ViewType属性的信息,这可能会有所帮助。在我的简单测试中,两者都Panes(2)有效,Panes(3)但你可以有不同的调用你的子的上下文。

于 2013-05-20T17:58:14.000 回答