我有一些代码需要我知道什么SlideIndex
进行操作(例如,在哪里插入新幻灯片、在哪里插入 ChartObject 等)。大约99%的情况下,我都能成功获得SlideIndex
by:
Dim w as Long 'slide index variable
w = ActivePresentation.Windows(1).Selection.SlideRange(1).SlideIndex
另外 0.1% 的时间,当ActivePresentation.Windows(1).SelectionType = ppSelectionNone
,它会失败,因为(可以理解)它无法获得SlideIndex
的选择,因为没有选择。如果用户无意中“选择”了“大纲”窗格中两张幻灯片之间的空间,则可能会发生这种情况。
理想情况下,我想做的是得到SlideIndex
在“幻灯片”窗格中可见的幻灯片的属性:
I currently have some code that tests whether the SelectionType
is ppSelectionNone
, so I can trap the condition, I just have not figured a way to identify the slideIndex of the Slides Pane.
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
Update
我的临时解决方案是使用公共变量lastUsedSlide
试图跟踪最近选择的幻灯片。我可以将其与WindowSelectionChange
事件,但希望有一个更直接的解决方案。如果我认为这个方法可以always工作,我会使用它,但是,它可能会引入不可预见的错误,因为lastUsedSlide
不是可靠的代理what_slide_i_am_currently_looking_at
.