如何获取一个部分中第一张幻灯片的幻灯片编号?
How to get slide number of first slide in a section?
我正在尝试仅对特定部分中的幻灯片进行编号。为此,我需要为每张幻灯片生成编号。设 first 为该部分中第一张幻灯片的幻灯片编号。那么,该节每张幻灯片的编号公式为:
Number = Current slide number - first + 1
我目前有代码可以提供当前幻灯片编号(文本在一个形状内,无需担心)。
.Text = "Add. Info" & vbNewLine & _
ActiveWindow.View.Slide.SlideIndex
我要查找的部分名为 AddInfo。
如何获取该部分中第一张幻灯片的幻灯片编号?
要获取特定部分的第一张幻灯片,您可以使用以下函数:
' Returns the index of the first slide under the section `sectionName`.
' Returns -1 if the section is not found or doesn't have any slides.
Public Function GetFirstSlideNumber(ByVal sectionName As String) As Long
With ActivePresentation.SectionProperties
Dim i As Long
For i = 1 To .Count
If .Name(i) = sectionName Then
GetFirstSlideNumber = .firstSlide(i)
Exit Function
End If
Next
End With
' Section not found.
GetFirstSlideNumber = -1
End Function
用法:
Debug.Print GetFirstSlideNumber("AddInfo")
我正在尝试仅对特定部分中的幻灯片进行编号。为此,我需要为每张幻灯片生成编号。设 first 为该部分中第一张幻灯片的幻灯片编号。那么,该节每张幻灯片的编号公式为:
Number = Current slide number - first + 1
我目前有代码可以提供当前幻灯片编号(文本在一个形状内,无需担心)。
.Text = "Add. Info" & vbNewLine & _
ActiveWindow.View.Slide.SlideIndex
我要查找的部分名为 AddInfo。
如何获取该部分中第一张幻灯片的幻灯片编号?
要获取特定部分的第一张幻灯片,您可以使用以下函数:
' Returns the index of the first slide under the section `sectionName`.
' Returns -1 if the section is not found or doesn't have any slides.
Public Function GetFirstSlideNumber(ByVal sectionName As String) As Long
With ActivePresentation.SectionProperties
Dim i As Long
For i = 1 To .Count
If .Name(i) = sectionName Then
GetFirstSlideNumber = .firstSlide(i)
Exit Function
End If
Next
End With
' Section not found.
GetFirstSlideNumber = -1
End Function
用法:
Debug.Print GetFirstSlideNumber("AddInfo")